[ncl-talk] Plotting XY graph (similar to example 5)
Klemm, Toni
toni at ou.edu
Thu Sep 28 10:07:47 MDT 2017
Hi!
I am trying to plot monthly data of threshold exceedance from a precipitation dataset I created prior. The data is already prepared and from 1980 to 2014 in monthly resolution (420 values). My problem is, the plot doesn’t plot the data per month and year but plots all 12 values on the full year and then jumps to the next year (say 1980 -> 1981 -> 1982) instead of the individual months (basically: 1980/1 -> 1980/2 -> 1980/3 etc.). I did create a float dateF variable as described in example 5 (https://www.ncl.ucar.edu/Applications/Scripts/xy_5.ncl, plot here: https://www.ncl.ucar.edu/Applications/Images/xy_5_1_lg.png) but the plots still didn’t change.
My script is written using example 5 as a rough template.
Below is my script, and attached are two zip files with my data to test, and two plots from 1980 to 1989 as it looks right now.
I would appreciate any help and thank you for your time!
Best,
Toni
Toni Klemm
Ph.D. Candidate
The University of Oklahoma
South Central Climate Science Center
phone: 405 325 1272
Contributor at the Early Career Climate Forum<https://www.eccforum.org/>
www.toni-klemm.de<http://www.toni-klemm.de/> | @toniklemm<https://twitter.com/ToniKlemm>
; *************************************************************************************************************
; Compare maximum and total number of monthly threshold exceedance days for 95th percentile and 99th percentile
; *************************************************************************************************************
;
; Used as template: https://www.ncl.ucar.edu/Applications/Scripts/xy_5.ncl
;
begin
print("**** Start ****")
; ***********************************************
; 1 - READ IN FILES
; ***********************************************
print("1 - Read in q95 and q99 data")
q95_files = systemfunc("ls ~/OBS/PRECIP/daily/threshold/by_month_and_year/q95/nc/*.nc")
q95_f = addfiles(q95_files,"r")
ListSetType(q95_f,"join")
q99_files = systemfunc("ls ~/OBS/PRECIP/daily/threshold/by_month_and_year/q99/nc/*.nc")
q99_f = addfiles(q99_files,"r")
ListSetType(q99_f,"join")
; ***********************************************
; 2 - READ IN VARIABLES
; ***********************************************
print("2 - Read in q95 and q99 variables")
max_yes_95 = q95_f[:]->max_yes_95
min_max_yes_95 = min(max_yes_95)
max_max_yes_95 = max(max_yes_95)
total_yes_95 = q95_f[:]->total_yes_95
min_total_yes_95 = min(total_yes_95)
max_total_yes_95 = max(total_yes_95)
max_yes_99 = q99_f[:]->max_yes_99
min_max_yes_99 = min(max_yes_99)
max_max_yes_99 = max(max_yes_99)
total_yes_99 = q99_f[:]->total_yes_99
min_total_yes_99 = min(total_yes_99)
max_total_yes_99 = max(total_yes_99)
date = q95_f[:]->date
dimDate = dimsizes(date)
dateF = new(dimDate,float)
do n=0,dimDate-1 ; date = 198001
yyyy = date(n)/100 ; yyyy = 1980
mon = date(n)-yyyy*100 ; mon = 198001 - (1980*100) = 1
dateF(n) = yyyy + (mon-1)/12 ; dateF(n) = 1980 + (1-1)/12 = 1980.0833
print("date(n) = " + date(n) + "(" + n + ")")
print("yyyy = " + yyyy)
print("mon = " + mon)
print("dateF(n) = " + dateF(n) + "(" + n + ")")
print("max_yes_95(n) = " + max_yes_95(n) + "(" + n + ")")
end do
printVarSummary(dateF)
; print(max_yes_95)
; printVarSummary(dateF)
; printVarSummary(total_yes_95)
; printVarSummary(total_yes_99)
; printVarSummary(yyyymm)
; sleep(10)
;******************************************
; 3A - DEFINE XY PLOT FOR MAXIMA COMPARISON
;******************************************
print("3A - Define XY plot for maxima comparison")
diro = "~/OBS/PRECIP/daily/threshold/by_month_and_year/"
wks = gsn_open_wks ("png",diro + "obs_precip_SHP_daily_yes_no_xy_plot_max") ; send graphics to PNG file
res = True ; plot mods desired
res at gsnFrame = False ; don't advance frame yet
res at vpHeightF= 0.2 ; change aspect ratio of plot
res at vpWidthF = 0.7
res at gsnLeftString = "Range q95: " + min_max_yes_95 + " - " + max_max_yes_95 + " days" ; map subtitle, printed on the top left
res at gsnRightString = "Range q99: " + min_max_yes_99 + " - " + max_max_yes_99 + " days" ; map subtitle, printed on the top left
res at trYMinF = 0.0 ; min value on y-axis
res at trYMaxF = 8.0 ; max value on y-axis
; since we stretch the plot, we need to slide it over a bit so it does not
; run off the page. we do this by:
; res at vpXF = 0.1 ; start plot at x ndc coord
res at tiYAxisString = "Days per Month" ; y-axis label
res at tiYAxisFontHeightF = 0.012
res at tiMainString = "Maximum Days per Month > 95~S~th~N~ Percentile and 99~S~th~N~ Percentile" ; title
res at tiMainFontHeightF = 0.02
res at tiMainFont = 22
; create a reference line and shade values above and below with selected colors. This is shading array dsoid.
res at gsnYRefLine = 0.0 ; create a reference line
;*********************************
; polyline parameters used on both plots
;*********************************
polyres = True
polyres at gsLineThicknessF = 3.0
; polyres at gsLineColor = 4.0
;******************************************
; 3B - CREATE XY PLOT FOR MAXIMA COMPARISON
;******************************************
print("3B - Create XY plot for Maxima Comparison")
; res at gsnAboveYRefLineColor = "green" ; above ref line fill red
; res at gsnBelowYRefLineColor = "blue" ; below ref line fill blue
plot = gsn_csm_xy(wks,dateF,max_yes_95,res) ; create plot
gsn_polyline(wks,plot,dateF,(/max_yes_99/),polyres) ; add polyline
frame(wks) ; now advance frame
print("**** Done Maxima ****")
print("")
;******************************************
; 4A - DEFINE XY PLOT FOR TOTALS COMPARISON
;******************************************
print("4A - Define XY plot for totals comparison")
diro = "~/OBS/PRECIP/daily/threshold/by_month_and_year/"
wks = gsn_open_wks ("png",diro + "obs_precip_SHP_daily_yes_no_xy_plot_totals") ; send graphics to PNG file
res = True ; plot mods desired
res at gsnFrame = False ; don't advance frame yet
res at vpHeightF= 0.2 ; change aspect ratio of plot
res at vpWidthF = 0.7
res at gsnLeftString = "Range q95: " + min_total_yes_95 + " - " + max_total_yes_95 + " days" ; map subtitle, printed on the top left
res at gsnRightString = "Range q99: " + min_total_yes_99 + " - " + max_total_yes_99 + " days" ; map subtitle, printed on the top left
res at trYMinF = 0.0 ; min value on y-axis
res at trYMaxF = 800.0 ; max value on y-axis
; since we stretch the plot, we need to slide it over a bit so it does not
; run off the page. we do this by:
; res at vpXF = 0.1 ; start plot at x ndc coord
res at tiYAxisString = "Days per Month" ; y-axis label
res at tiYAxisFontHeightF = 0.012
res at tiMainString = "Total Days per Month > 95~S~th~N~ Percentile and 99~S~th~N~ Percentile" ; title
res at tiMainFontHeightF = 0.02
res at tiMainFont = 22
; create a reference line and shade values above and below with selected colors. This is shading array dsoid.
res at gsnYRefLine = 0.1 ; create a reference line
;*********************************
; polyline parameters used on both plots
;*********************************
polyres = True
polyres at gsLineThicknessF = 3.0
; polyres at gsLineColor = 4.0
;******************************************
; 4B - CREATE XY PLOT FOR TOTALS COMPARISON
;******************************************
print("4B - Create XY plot for totals comparison")
; res at gsnAboveYRefLineColor = "green" ; above ref line fill red
; res at gsnBelowYRefLineColor = "blue" ; below ref line fill blue
plot = gsn_csm_xy(wks,dateF,total_yes_95,res) ; create plot
gsn_polyline(wks,plot,dateF,(/total_yes_99/),polyres) ; add polyline
frame(wks) ; now advance frame
print("**** Done Totals ****")
end
[cid:409ef8d3-680a-4f3d-bf2c-b72d15b0708e at namprd03.prod.outlook.com]
[cid:33fa7a1f-0331-4cba-a36f-05911bce70c2 at namprd03.prod.outlook.com]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170928/cc42f058/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: obs_precip_SHP_daily_yes_no_xy_plot_max.png
Type: image/png
Size: 67638 bytes
Desc: obs_precip_SHP_daily_yes_no_xy_plot_max.png
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170928/cc42f058/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: obs_precip_SHP_daily_yes_no_xy_plot_totals.png
Type: image/png
Size: 62124 bytes
Desc: obs_precip_SHP_daily_yes_no_xy_plot_totals.png
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170928/cc42f058/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: q95.zip
Type: application/zip
Size: 642460 bytes
Desc: q95.zip
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170928/cc42f058/attachment-0002.zip>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: q99.zip
Type: application/zip
Size: 603601 bytes
Desc: q99.zip
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170928/cc42f058/attachment-0003.zip>
More information about the ncl-talk
mailing list