[ncl-talk] can not create year labels for x axis
Mary Haley
haley at ucar.edu
Thu Jan 5 09:08:12 MST 2017
Dhirendra,
First, a couple of NCL tips:
1)
You don't need to use a "do" loop to do simple array arithmetic. You can
replace the following code:
dateF = new (dimDate, float)
do n=0,dimDate-1
yyyy = date(n)/100
mon = date(n)-yyyy*100
dateF(n) = tofloat(yyyy + (mon-1)/12.)
end do
with:
yyyy = date/100
mon = date-yyyy*100
dateF = tofloat(yyyy + (mon-1)/12.)
2) We have a function that converts YYYYMM to YYYY.frac, so the above code
can be replaced with
one line:
dateF = yyyymm_to_yyyyfrac(date,0.0)
The values on your X axis look suspicious to me, as they go from around
7000 to over 10000. Are these really your year values? Did you look at the
original "date" variable to make sure these values are actually YYYYMM?
printVarSummary(date)
printMinMax(date)
You should also do:
print(date)
to see what all the numbers look like.
To get nice labels on a time axis, I highly recommend the use of the
time_axis_labels function:
http://www.ncl.ucar.edu/Document/Functions/User_contributed/time_axis_labels.shtml
You have lots of options for how to format your labels.
You can see some examples of how to use this at:
http://www.ncl.ucar.edu/Applications/time_labels.shtml
In particular, look at time_labels_4.ncl. This shows how to plot time data
that is in a YYYYMM format. I'm not sure your time is in this format, but
hopefully the above page will give you enough information to format your X
labels the way you want them.
--Mary
On Thu, Jan 5, 2017 at 8:09 AM, Dhirendra Kumar <dhirendra.cub at gmail.com>
wrote:
> Hi
>
> I am trying to plot an nc file having anomaly time series for the JJAS
> season. I have tried to follow the sample scripts over the NCL web
> resource, but could not succeed in getting the correct labels of time
> (year) on the X axis.
>
> Would appreciate if anybody could help...
> the script is as following-
>
> begin
> f = addfile ("std_tim_anomaly.nc", "r") ; add file
> date = f->time
> printVarSummary(date)
> precip= f->tp(:,0,0)
> printVarSummary(precip)
>
> dimDate = dimsizes(date) ; number of dates
>
> ; convert integer YYYYMM to float
>
> dateF = new (dimDate, float)
> do n=0,dimDate-1
> yyyy = date(n)/100
> mon = date(n)-yyyy*100
> dateF(n) = tofloat(yyyy + (mon-1)/12.)
> end do
>
> ;*********************************
> ; create plot
> ;********************************
> wks = gsn_open_wks ("ps", "bar" ) ; send graphics to PS file
> res = True ; plot mods desired
> res at gsnScale = True
>
> ; these four resources allow the user to stretch the plot size, and
> ; decide exactly where on the page to draw it.
>
> res at vpXF = 0.10 ; In page coordinates, where to start
> res at vpYF = 0.75 ; the plot
> res at vpHeightF = 0.43 ; Changes the aspect ratio
> res at vpWidthF = 0.85
>
> res at trYMinF = -3.0 ; min value on y-axis
> res at trYMaxF = 3.0 ; max value on y-axis
>
> res at tiYAxisString = "Anomalies" ; y-axis label
> ; this resource changes a regular line plot to a bar chart
> res at gsnXYBarChart = True ; create bar chart
> ; this resource is required to get bars above and below a reference line
> res at gsnYRefLine = 0. ; reference line
> res at gsnXYBarChart = True ; create bar chart
> res at gsnAboveYRefLineColor = "red" ; above ref line fill red
> res at gsnBelowYRefLineColor = "blue" ; below ref line fill blue
> res at gsnXYBarChartBarWidth = 24.0
> plot = gsn_csm_xy (wks,dateF(::),precip,res)
> end
>
> [image: Inline image 1]this is the plot which is being created.
>
> Thanks in anticipation.
>
> --
> ========================================
> Dhirendra Kumar
> PhD Student
> School of Environmental Sciences, JNU
> New Delhi (India)
> Contact: +91 9910778043 <+91%2099107%2078043>
> Alternate email: dhirendra.cub at outlook.com
> =========================================
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170105/e3ed07ab/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 13157 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170105/e3ed07ab/attachment.png
More information about the ncl-talk
mailing list