[ncl-talk] How to use time metadata / change time tick labels using gsn_csm_contour?
Mary Haley
haley at ucar.edu
Sat Aug 9 23:03:17 MDT 2014
Hi Michael,
Putting time values on the X axis in a nicely formatted way requires
setting three "tmXB" resources:
res at tmXBMode = "Explicit"
res at tmXBValues = ...
res at tmXBLabels = ...
The "tmXBValues" needs to be an array of values where you want tickmark
labels, and the "tmXBLabels" needs to be an array of the same size
containing the labels you want.
The array of values have to correspond to the time values representing your
X axis, and not index values. Time values can come in many different
formats, and that's why it was suggested you use "cd_calendar" to convert
them to a format that's easy to process.
You may be able to get by without having to use "cd_calendar", and instead
you can use "time_axis_labels", which will set those three resources for
you. Please see:
http://www.ncl.ucar.edu/Applications/time_labels.shtml
The first example shows how to set the tickmark labels by setting those
three resources, and the second example shows how to do it using
time_axis_labels.
If you have further questions about this, it would help if you provided a
"printVarSummary" of your time array, and a description of what kind of
labels you want on the X axis.
--Mary
On Fri, Aug 8, 2014 at 3:16 AM, Hemming, Michael <
michael.hemming at mpimet.mpg.de> wrote:
> Hello,
>
> I am creating panel plots using gsn_csm_contour. The data I use has been
> chosen from a 4d matrix prior to plotting. The metadata is correct for
> longitude but not for the time axis. I would like to show the time in
> years, 1-100.
>
> time metadata:
>
> tho = hours, 365_day
> potT = days, preleptic_gregorian
>
>
> Here is my code:
>
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
>
> ;##########################################################################
> ;##########################################################################
> ;-------------------------Temperature Profile------------------------------
> ;--------------------------------------------------------------------------
> ;##########################################################################
> ;##########################################################################
>
> ;----------Load in data
>
> ;MPIOM
>
> data12 = addfile ("sector.nc", "r")
> tho = data12->tho
>
>
> variables = getfilevarnames(data12)
>
> print(" ")
> print(" MPIOM temperature data Information:")
> print(" ")
> print(variables)
> printVarSummary(tho)
>
> ;ICON
>
> noshupw = addfile ("con.nc", "r")
> potT = noshupw->t_acc
> potT&lon = potT&lon-360 ; Fix the longitudes to be < 360
>
>
> ;variables = getfilevarnames(noshupw)
> print(" ")
> print("ICON temperature data information:")
> print(" ")
> print(variables)
> printVarSummary(potT)
>
>
>
> ;--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%
>
> ;--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%
>
> ;--------------Hovmuller T comparison plots
>
>
> ;--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%
>
> ;--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%--%
>
> ;http://www.ncl.ucar.edu/Applications/Scripts/lat_time_3.ncl
>
> ;*********************************************
> ; manipulate data for plotting
> ;*********************************************
>
> dm = rm_single_dims(tho({depth|7},{lon|-30:-30},lat|:,time|:))
> di = rm_single_dims(potT({depth|7},{lon|-30:-30},lat|:,time|:))
>
> dm30S = rm_single_dims(tho({depth|7},lon|:,{lat|-30:-30},time|:))
> di30S = rm_single_dims(potT({depth|7},lon|:,{lat|-30:-30},time|:))
>
> dmeq = rm_single_dims(tho({depth|7},lon|:,{lat|0:0},time|:))
> dieq = rm_single_dims(potT({depth|7},lon|:,{lat|0:0},time|:))
>
> dm30N = rm_single_dims(tho({depth|7},lon|:,{lat|30:30},time|:))
> di30N = rm_single_dims(potT({depth|7},lon|:,{lat|30:30},time|:))
>
>
> printVarSummary(dm)
> printVarSummary(di)
> printVarSummary(dm30S)
> printVarSummary(di30S)
>
> ;------Plotting
>
> wks = gsn_open_wks("x11", "T)
>
> res = True
> res at cnFillOn = True
>
> plot = new(2,graphic)
>
> res at gsnDraw = False ; don't
> draw
> res at gsnFrame = False ;
> don't advance frame
>
> resP = True ;
> modify the panel plot
> resP at gsnMaximize = True
> res at tiMainFontHeightF = 0.02
> resP at txFontHeightF = 0.015
> resP at txString = "Temperature at the surface with time
> at a longitude of 30W"
>
> res at tiMainString = "M"
> plot(0) = gsn_csm_contour(wks,dm,res)
>
> res at tiMainString = "I"
> plot(1) = gsn_csm_contour(wks,di,res)
>
> ;gsn_panel(wks,plot,(/1,2/),resP)
>
> ;----------------------------surface plot
>
>
> wks = gsn_open_wks("x11", "T_HOVMULLER_MPIOM_ICON_surface_30N")
>
> res = True
> res at cnFillOn = True
>
> plot1 = new(2,graphic)
>
> res at gsnDraw = False ; don't
> draw
> res at gsnFrame = False ;
> don't advance frame
>
>
> resP at gsnMaximize = True
> res at tiMainFontHeightF = 0.02
> resP at txFontHeightF = 0.015
> resP at txString = "Temperature at the surface with time
> at a latitude of 30N"
> res at lbLabelBarOn = False
> res at cnLevelSelectionMode = "ManualLevels"
> res at cnMinLevelValF = 3.
> res at cnMaxLevelValF = 7.
> res at cnLevelSpacingF = 0.2
> res at cnSpanFillPalette = True
> resP at gsnPanelLabelBar = True
>
> res at tiMainString = "M
> plot1(0) = gsn_csm_contour(wks,dm30N,res)
>
> res at tiMainString = "I
> plot1(1) = gsn_csm_contour(wks,di30N,res)
>
> gsn_panel(wks,plot1,(/1,2/),resP)
>
>
>
>
> I have been told I can use cd_calendar but this involves creating a new
> variable 'time' which I would like to avoid. Another option was to change
> the tick labels but I am not sure how to do this using gsn_csm_contour.
>
> thanks,
> Michael
>
>
> _______________________________________________
> ncl-talk mailing list
> 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/20140809/c3b770b8/attachment.html
More information about the ncl-talk
mailing list