[ncl-talk] If statement
Melissa Lazenby
M.Lazenby at sussex.ac.uk
Fri Feb 24 06:10:57 MST 2023
Hi All NCL Users
I am struggling with a conditional statement that I would like to perform.
Essentially, I am trying to make some bars pink instead of red to show a difference in uncertainty.
I have the following code below to perform this but I think there is an error with how I am looping the array.
do hh = 0,33
stdarr(hh,0) = (/ (yIndex(hh::34)) /)
if ((hh.eq.1) .or. (hh.eq.2) .or. (hh.eq.3)) then
sres at gsnXYBarChartColors = (/"pink"/)
else
sres at gsnXYBarChartColors = (/"red"/)
end if
plot1 = gsn_csm_xy(wks,fspan(1855.6,1888.7,34),stdarr(hh,0),sres) ; draw each time series
end do
This error occurs:
(0) gsn_csm_xy: Fatal: X and Y must have the same dimensions sizes, or one must be one-dimensional and both have the same rightmost dimension.
Any help on this would be much appreciated!
Many thanks!
Kindest Regards
Melissa
Full Code:
;*******************************************************
; Mpwapwa.ncl
;
; Concepts illustrated:
; - Drawing multiple bar charts on a page
; - Drawing three custom legends outside a bar chart
; - Using bar charts to draw standard deviations for four time series
; - Drawing a time series plot
;*******************************************************
;
; These files are loaded by default in NCL V6.2.0 and newer
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
begin
x = (/1856, 1857, 1858, 1859, 1860, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889/)
yIndex = (/0,2,-1,-3,2,0,0,0,0,0,0,0,0,0,0,0.05,2,0,-1,-1,-2,1,1,-2,-2,1,-1,-3,0.05,0.05,0.05,-3,0.05,0/)
y20CR3 = (/-1.7049024, -1.9956352, 0.1017878, 1.5787968, 0.2902762, 0.1615032, 0.7573914, 0.127654184, 0.3391526, 0.18975348, 1.4533978, 0.28738338, 0.8228474, -1.2142216, 0.67589808, 1.3983746, 1.1087944, 0.58095216, -1.3422622, 0.226781852, 2.173188, 0.6511904, 0.9723054, -0.4989326, -1.5402072, -0.1535788, -0.226605, -1.6808838, -0.19809544, -0.1772666, 0.0769234, -0.6346154, -1.2222682, -0.0073483/)
;scaled by 5 and deleted first value to go for year 2.
yCMIP5 = (/-0.9094243, 0.5458735, -0.8682191, -1.826278, -0.6501346, 0.1305088, 0.51643, 0.6247665, -0.4082086, 0.3641764, 1.476322, 0.842743, -0.5013026, -0.1281874, 0.4829363, -0.7015711, 0.269588, -0.2834916, -0.8827865, -0.4242322, -1.171241, -0.8289737, -0.4638377, 0.8812776, 0.5154026, -1.191759 ,0.8223722, -1.198702, -0.8878552, -1.724694, -1.62958, 1.02131, -1.440305, -2.299565/)
stdarr = new((/34,3/),"float")
do hh = 0,33
stdarr(hh,0) = (/ (yIndex(hh::34)) /)
stdarr(hh,1) = (/ (y20CR3(hh::34)) /)
stdarr(hh,2) = (/ (yCMIP5(hh::34)) /)
end do
print("Index Data = "+dimsizes(yIndex)+", 20CR3 = "+dimsizes(y20CR3)+", CMIP5 = "+dimsizes(yCMIP5))
printVarSummary(stdarr)
;======================================================================================
wks = gsn_open_wks("X11","Mpwapwa_3_Plot") ; send graphics to PNG file
sres = True
sres at trXMinF = 1855
sres at trXMaxF = 1890
sres at tmXBValues = ispan(1855,1890,5) ; create major tickmarks with labels every 5 years
sres at tmXBLabels = sres at tmXBValues
sres at tmXBMinorValues = ispan(1855,1890,1) ; as tmXBMode = "Explicit", this resource needs to be set to get minor tickmarks. Create minor tickmarks every year.
sres at vpWidthF = 0.8
sres at vpHeightF = 0.5
sres at vpXF = .15
sres at trYMinF = -3.5
sres at trYMaxF = 3.5
sres at gsnDraw = True
;sres at gsnFrame = False
sres at gsnXYBarChart = True
sres at gsnXYBarChartBarWidth = 0.20 ; change bar widths
sres at tmXBMode = "Explicit" ; explicit labels
sres at tmXBLabelFontHeightF = 0.0205
sres at tmXTLabelFontHeightF = 0.0205
sres at tmYLLabelFontHeightF = 0.0225
sres at tiMainFontHeightF = 0.025
sres at tiMainFont = "helvetica"
sres at tiMainString = "Precipitation Anomalies for Mpwapwa"
sres at gsnRightString = ""
sres at tiYAxisString = "Pr Anomalies (mm/day) DJFMA"
sres at gsnYRefLine = 0. ; reference line
do hh = 0,33
stdarr(hh,0) = (/ (yIndex(hh::34)) /)
if ((hh.eq.1) .or. (hh.eq.2) .or. (hh.eq.3)) then
sres at gsnXYBarChartColors = (/"pink"/)
else
sres at gsnXYBarChartColors = (/"red"/)
end if
plot1 = gsn_csm_xy(wks,fspan(1855.6,1888.7,34),stdarr(hh,0),sres) ; draw each time series
end do
sres at gsnXYBarChartColors = (/"black"/) ; seperately, not
plot2 = gsn_csm_xy(wks,fspan(1855.8,1888.9,34),stdarr(:,1),sres) ; advancing the frame
sres at gsnXYBarChartColors = (/"blue"/) ; drawn on the X-axis
plot3 = gsn_csm_xy(wks,fspan(1856.4,1889.2,34),stdarr(:,2),sres)
lbres = True ; labelbar only resources
lbres at vpWidthF = 0.2 ; labelbar width
lbres at vpHeightF = 0.1 ; labelbar height
lbres at lbBoxMajorExtentF = 0.56 ; puts space between color boxes
lbres at lbMonoFillPattern = True ; Solid fill pattern
lbres at lbLabelFontHeightF = 0.025 ; font height. default is small
lbres at lbLabelJust = "CenterLeft" ; left justify labels
lbres at lbPerimOn = False
lbres at lgPerimColor = "white"
colors = (/"red", "black", "blue"/)
labels = (/"Index", "Reanalysis", "CMIP5"/)
xpos = (/0.15, 0.40, 0.7/)
do i=0,2
lbres at lbFillColors = colors(i)
gsn_labelbar_ndc(wks,1,labels(i),xpos(i),0.20,lbres)
end do
frame(wks)
end
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
[cid:a164c079-9320-46e5-877d-0852711e5ddb]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230224/a5cf5247/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Outlook-wdomdmsr.png
Type: image/png
Size: 24937 bytes
Desc: Outlook-wdomdmsr.png
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230224/a5cf5247/attachment.png>
More information about the ncl-talk
mailing list