# [ncl-talk] Spectral Analysis (Period in X-axis)

Mon Jun 19 10:48:33 MDT 2017

```Hi SBR,
First, welcome to NCL! As you are a new user we strongly recommend that you
read through the NCL User Guide and the Mini-Language manual, both linked
from here:
http://www.ncl.ucar.edu/Document/Manuals/

"I want to keep the Y axis as it is but want to change the X axis to
Period with scale 4 8 16 32 64 128 256 512."

I think you need to set the following:
r at xyXStyle = "Irregular"
r at xyXIrregularPoints = (/.01,.1,.2,.25,.5/)
Note that the setting of xyXIrregularPoints in purely subjective. The
spacing between each value on the X-axis will be the same regardless of the
size of the value, so set this however you want.

If you want the labels of the X-axis to be 4 8 16 32 64 128 256 512, then
you need to set the tmXBValues and tmXBLabels resources as I suggested in
my initial reply. Note that to set these resources the formula to use is:
1/frequency = period, or 1/tmXBValues = tmXBLabels. As an example, for the
returned spectra the smallest period will be 2 years, and the frequency is
.5.  (1/.5 = 2)

Here would be the settings for your first 4 labels; I leave the rest for
you to calculate.
r at tmXBValues = (/.03125,.0625,.125,.25/)
r at tmXBLabels = (/"32","16","8","4"/)

If you want the periods (frequency) to increase (decrease) along the x-axis
as opposed to decreasing (increasing), you can set r at trXReverse = True
http://www.ncl.ucar.edu/Document/Graphics/Resources/tr.shtml#trXReverse

Finally, colleague sent in an example spectra script that sets various
options and walks one through an alternative way to create a spectra plot
with the period as the x-axis.  I have attached it here.

Hope that helps. If you have any further questions please reply to the
ncl-talk email list.

On Fri, Jun 16, 2017 at 7:51 PM, S. B. Ratna <sbratna2012 at gmail.com> wrote:

> Thanks for your reply. I am a new user of NCL and difficult to
> understand many things now.
> I am trying to modify the following code as per your instructions.
> https://www.ncl.ucar.edu/Applications/Scripts/spec_4.ncl
>
> I want to keep the Y axis as it is but want to change the X axis to
> Period with scale 4 8 16 32 64 128 256 512.
> Could you please suggest how to change this part of the code.
>
> ;************************************************
> ; plotting
> ;************************************************
>    wks  = gsn_open_wks("ps","spec")              ; Opens a ps file
>
>    r = True                                      ; plot mods desired
>    r at tiMainString = "SOI"                        ; title
>    r at tiXAxisString = "Frequency (cycles/month)"  ; xaxis
>    r at tiYAxisString = "Variance"                  ; yaxis
> ;***********************************************
> ; Generate log plot showing "red noise" confidence bounds
> ; (a) log scaling and (b) the Band Width
> ;***********************************************
>    r at trYLog              = True                 ; log scaling
>    r at trYMinF             = 0.10                 ; manually set lower limit
>    r at trYMaxF             = 30.0                 ;   "          upper
>    r at gsnFrame            = False                ; do not advance frame
>    plot  = gsn_csm_xy(wks,sdof at frq, splt,r)
>
>    xf   = (/0.40, 0.40+sdof at bw/)                ; Create band width line
>    ys   = 0.75*max(sdof at spcx)                   ; 75% up Y axis
>    yv   = (/ys,ys/)
>    rpl  = True                                  ; resources for polyline
>    rpl at gsLineThicknessF  = 2                    ; Define line thickness
>    gsn_polyline(wks,plot,xf,yv,rpl)             ; Draw BandWidth
>
>    txres= True                                  ; label BW line
>    txres at txFontHeightF = 0.015                  ; font height
>    txres at txJust        = "CenterLeft"           ; Set lable location
>    gsn_text(wks,plot,"BW",0.41+sdof at bw,ys,txres); Label
>    frame (wks)
> end
>
> Thanks.
> SBR
>
> On Fri, Jun 16, 2017 at 10:57 PM, Adam Phillips <asphilli at ucar.edu> wrote:
> > Hi SBR,
> > To switch to period being on the bottom y-axis you can do something like
> > this:
> > pres at tmXBMode   = "Explicit"
> > pres at tmXBValues = (/".02",".10",".20",".3333",".50"/)
> > pres at tmXBLabels = (/"50","10","5","3","2"/)
> > pres at tiXAxisString = "Period (years)"
> >
> > To alter the Y-axis type, you can set trYAxisType and trYCoordPoints as
> is
> > done in XY example #30 here:
> > http://www.ncl.ucar.edu/Applications/xy.shtml#ex30
> >
> > Hope that helps. If you have any further questions please respond to the
> > ncl-talk email list.
> >
> >
> >
> >
> >
> > On Fri, Jun 16, 2017 at 12:52 PM, S. B. Ratna <sbratna2012 at gmail.com>
> wrote:
> >>
> >> Hi All,
> >> I would like to plot the spectral analysis for my annual mean data for
> >> about 800 years. I would like to use 'spec_4.ncl' but I need "period
> >> (year)" in the X-axis instead of "Frequency".
> >> Also, the X-axis scale should be 4 8 16 32 64 128 256 512.
> >> Could you please suggest how to draw such figure.
> >> https://www.ncl.ucar.edu/Applications/Scripts/spec_4.ncl
> >>
> >> Thanks.
> >> SBR
> >> _______________________________________________
> >> ncl-talk mailing list
> >> ncl-talk at ucar.edu
> >> List instructions, subscriber options, unsubscribe:
> >> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
> >
> >
> >
> >
> > --
> > Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
> > www.cgd.ucar.edu/staff/asphilli/   303-497-1726
> >
>

--
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170619/8b7ddbc5/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spec.ncl
Type: text/x-ncl
Size: 3592 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170619/8b7ddbc5/attachment.bin
```