[ncl-talk] XY Plot with Precip vs Time
Adam Phillips
asphilli at ucar.edu
Wed Nov 16 10:15:08 MST 2022
Hi Melissa,
There are numerous ways to go about it, including setting the
tmXBMode/tmXBValues/tmXBLabels
<https://www.ncl.ucar.edu/Applications/tickmarks.shtml#ex2> resources. In
this particular case though, it is likely easiest to just modify the
specified x-axis values in the plot call. Try changing this:
plot1=gsn_csm_xy(wks,pr&time,pr(:,0,0),res)
to this:
plot1=gsn_csm_xy(wks,ispan(1856,1890,1),pr(:,0,0),res)
If you want to change the labels themselves you will have to use the
tmXBMode/tmXBValues/tmXBLabels resources. The values input to tmXBValues
must be in the range of values specified in your x-axis input in the plot
call. For example, this will work:
res at tmXBMode = "Explicit"
res at tmXBValues = (/1860,1870,1880,1890/)
res at tmXBLabels = res at tmXBValues
plot1=gsn_csm_xy(wks,ispan(1856,1890,1),pr(:,0,0),res)
but this will not:
res at tmXBMode = "Explicit"
res at tmXBValues = (/1860,1870,1880,1890/)
res at tmXBLabels = res at tmXBValues
plot1=gsn_csm_xy(wks,pr&time,pr(:,0,0),res)
Finally, if you set tmXBMode = "Explicit" you will lose the minor tick
marks. To get them back, set tmXBMinorValues.
Hope that helps!
Adam
On Wed, Nov 16, 2022 at 4:38 AM Melissa Lazenby via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:
> Dear All NCL Users
>
> I am having trouble displaying my x-axis correctly for an XY plot with
> precip anomalies vs time.
> Below is the figure and code:
>
>
> I just would like to have my x-axis represent my time data which is in
> years from 1856-1890.
>
> Any help would be greatly appreciated.
>
> ;************************************************
> ; Concepts illustrated:
> ; - Drawing a xyplot
> ;************************************************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> ;************************************************
> begin
> ;************************************************
> ; variable and file handling
> ;************************************************
> in =
> addfile("/mnt/geog/ml382/ml382_sals000408_home_dir/melsicz/mpwapwa/ENSMEAN/pr_Amon_ENSMEAN_historical_mpwapwa_1856-1890_NDJFMA_NEW_ANOM_YMONMEAN.nc","r")
>
>
> pr = in->pr(:,0,:,:)
>
> print(pr)
>
> ;************************************************
> ; plotting
> ;************************************************
> wks = gsn_open_wks("X11","Figure_Mpwapwa_20CR") ; Opens
> a ps file
>
> res = True
> res at gsnMaximize = True
> res at tiXAxisString = "Years 1856-1890 (NDJFMA)" ;
> x-axis label
> res at tiYAxisString = "Precipitation Anomaly" ; y-axis
> label
> res at xyLineLabelsOn = True ; no contour line
> labels
> ;res at trXMinF = 1856 ; min level
> ;res at trXMaxF = 1890 ; max level
> res at xyLineThicknessF = 4.0
> res at lgLineThicknessF = 2.0
>
> res at gsnDraw = False ; do not draw the plot
> res at gsnFrame = False
> ;res at pmLegendDisplayMode = "Always" ; Display a legend.
>
> res at pmLegendParallelPosF = 1.25 ; move units right
> res at pmLegendOrthogonalPosF = -0.9 ; move units down
> res at lgBoxMinorExtentF = 0.3
> res at pmLegendWidthF = 0.1
> res at lgLabelFontHeightF = 0.015 ; Change the font size
> res at pmLegendHeightF = 0.2
>
> res at gsnXYBarChart = True
> res at xyLineColors = (/"blue", "red"/)
> res at tiMainString = "CMIP5 ENSMEAN Precipitation Anomalies over Mpwapwa"
> res at gsnYRefLine = 0. ; reference line
>
>
> plot1=gsn_csm_xy(wks,pr&time,pr(:,0,0),res)
>
> draw(plot1)
> frame(wks)
>
> end
>
> Kindest Regards
> Melissa
>
> Dr. Melissa Lazenby
> Lecturer in Climate Change
> Department of Geography
> Chichester 1 C150
> University of Sussex
>
> *"Education is the most powerful weapon which you can use to change the
> world" Nelson Mandela*
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
--
Adam Phillips
Associate Scientist IV, Climate Analysis Section
Climate and Global Dynamics Laboratory
National Center for Atmospheric Research
www.cgd.ucar.edu/staff/asphilli/
<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221116/c328c9bf/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 57655 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221116/c328c9bf/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Outlook-v1qhdcap.png
Type: image/png
Size: 24937 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221116/c328c9bf/attachment-0001.png>
More information about the ncl-talk
mailing list