<div dir="ltr">Hi Melissa,<div>I would create an array of strings pertaining to the individual bar colors, like this:</div><div>bc = new(34,string)</div><div>bc = "red"</div><div>time = ispan(1855,1888,1)</div><div>selyr = (/1857,1858,1859/) </div><div>do gg = 0,dimsizes(selyr)-1</div><div> bc = where(time.eq.selyr(gg),"pink",bc)<br></div><div>end do</div><div>print(time+" "+bc)</div><div><br></div><div>and then you can tell NCL to color each bar by the bc array:</div><div>res@gsnXYBarChartColors2 = bc</div><div>plot1 = gsn_csm_xy(wks,fspan(1855.6,1888.7,34),stdarr(:,0),sres)</div><div>See the 2nd panel of example #6 here:<br></div><div><a href="https://www.ncl.ucar.edu/Applications/bar.shtml#ex6">https://www.ncl.ucar.edu/Applications/bar.shtml#ex6</a></div><div><br></div><div>Hope that helps!</div><div>Adam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 24, 2023 at 10:04 AM Melissa Lazenby via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Hi Dennis</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Many thanks for your speedy response. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I have gotten confused in which variable I am trying to set. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
What I actually want to do is select years which appear in the x axis differently based on their certainty. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
For example I want to make the year 1858 show up as a pink bar instead of a red bar to show less certainty. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Therefore I will need to make an if statement to reflect that for the x axis - however I have used the function fspan in my x value expression so not sure how to do this.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Would this maybe work?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
if ((fspan.eq.1857) .or. (fspan.eq.1858) .or. (fspan.eq.1859)) then
<div>sres@gsnXYBarChartColors = (/"pink"/) </div>
<div>else </div>
<div>sres@gsnXYBarChartColors = (/"red"/) </div>
<div>end if</div>
<div> plot1 = gsn_csm_xy(wks,fspan(1855.6,1888.7,34),stdarr(:,0),sres) </div>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Many thanks for all your help!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Kindest Regards</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Melissa</div>
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="m_2869186732328664211m_-2758451608644265370Signature">
<div>
<div style="font-family:Tahoma;font-size:13px"></div>
<div style="font-family:Tahoma;font-size:13px">
<div style="font-family:Tahoma;font-size:13px">Dr. Melissa Lazenby
<div>Lecturer in Climate Change</div>
<div>Department of Geography</div>
<div>Chichester 1 C150</div>
<div>University of Sussex</div>
<div><br>
</div>
<div><i style="color:inherit;font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit">"Education is the most powerful weapon which you can use to change the world" Nelson Mandela</i><br>
</div>
<div><i style="color:inherit;font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><br>
</i></div>
<div><i style="color:inherit;font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><img style="max-width: 100%;" src="cid:18685db63bd45fc2e572"><br>
</i></div>
</div>
</div>
</div>
</div>
</div>
<div id="m_2869186732328664211m_-2758451608644265370appendonsend"></div>
<hr style="display:inline-block;width:98%">
<div id="m_2869186732328664211m_-2758451608644265370divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Dennis Shea <<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>><br>
<b>Sent:</b> Friday, February 24, 2023 2:50 PM<br>
<b>To:</b> Melissa Lazenby <<a href="mailto:M.Lazenby@sussex.ac.uk" target="_blank">M.Lazenby@sussex.ac.uk</a>><br>
<b>Cc:</b> Ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>><br>
<b>Subject:</b> Re: [ncl-talk] If statement</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>I have not looked at the script but:</div>
<div>---<br>
</div>
<div>do hh = 0,33
<div> stdarr(hh,0) = (/ (yIndex(hh::34)) /)</div>
<div>---</div>
<div><br>
</div>
<div>hh is a scalar. So, when (say) hh=0</div>
<div><br>
</div>
<div> stdarr(0,0) = (/ (yIndex(0::34)) /) ; ==> 35 elements of yIndex <br>
</div>
<div><br>
</div>
<div>35 elements are being assigned to one array element.</div>
<div><br>
</div>
<div>NCL should have issued an error message.</div>
<div><br>
</div>
<div>Maybe, I am missing something!</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
<br>
<div>
<div dir="ltr">On Fri, Feb 24, 2023 at 6:11 AM Melissa Lazenby via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a>> wrote:<br>
</div>
<blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Hi All NCL Users</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I am struggling with a conditional statement that I would like to perform. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Essentially, I am trying to make some bars pink instead of red to show a difference in uncertainty. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I have the following code below to perform this but I think there is an error with how I am looping the array. </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
do hh = 0,33
<div> stdarr(hh,0) = (/ (yIndex(hh::34)) /)</div>
<div> </div>
<div> if ((hh.eq.1) .or. (hh.eq.2) .or. (hh.eq.3)) then</div>
<div>sres@gsnXYBarChartColors = (/"pink"/) </div>
<div>else </div>
<div>sres@gsnXYBarChartColors = (/"red"/) </div>
<div>end if</div>
<div> plot1 = gsn_csm_xy(wks,fspan(1855.6,1888.7,34),stdarr(hh,0),sres) ; draw each time series</div>
<div><br>
</div>
<div> end do</div>
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
This error occurs: </div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
(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.<br>
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Any help on this would be much appreciated!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Many thanks!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Kindest Regards</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Melissa</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Full Code:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
;*******************************************************
<div>; Mpwapwa.ncl</div>
<div>;</div>
<div>; Concepts illustrated:</div>
<div>; - Drawing multiple bar charts on a page</div>
<div>; - Drawing three custom legends outside a bar chart</div>
<div>; - Using bar charts to draw standard deviations for four time series</div>
<div>; - Drawing a time series plot</div>
<div>;*******************************************************</div>
<div>;</div>
<div>; These files are loaded by default in NCL V6.2.0 and newer</div>
<div> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div><br>
</div>
<div>begin</div>
<div> </div>
<div><br>
</div>
<div>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/)</div>
<div><br>
</div>
<div>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/)</div>
<div><br>
</div>
<div><br>
</div>
<div>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/)</div>
<div><br>
</div>
<div>;scaled by 5 and deleted first value to go for year 2. </div>
<div>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/)</div>
<div><br>
</div>
<div><br>
</div>
<div> stdarr = new((/34,3/),"float")</div>
<div> do hh = 0,33</div>
<div> stdarr(hh,0) = (/ (yIndex(hh::34)) /)</div>
<div> stdarr(hh,1) = (/ (y20CR3(hh::34)) /)</div>
<div> stdarr(hh,2) = (/ (yCMIP5(hh::34)) /)</div>
<div> end do</div>
<div> print("Index Data = "+dimsizes(yIndex)+", 20CR3 = "+dimsizes(y20CR3)+", CMIP5 = "+dimsizes(yCMIP5))</div>
<div><br>
</div>
<div>printVarSummary(stdarr)</div>
<div><br>
</div>
<div>;====================================================================================== </div>
<div> wks = gsn_open_wks("X11","Mpwapwa_3_Plot") ; send graphics to PNG file</div>
<div><br>
</div>
<div><br>
</div>
<div>sres = True</div>
<div><br>
</div>
<div> sres@trXMinF = 1855</div>
<div> sres@trXMaxF = 1890</div>
<div>sres@tmXBValues = ispan(1855,1890,5) ; create major tickmarks with labels every 5 years</div>
<div>sres@tmXBLabels = sres@tmXBValues</div>
<div>sres@tmXBMinorValues = ispan(1855,1890,1) ; as tmXBMode = "Explicit", this resource needs to be set to get minor tickmarks. Create minor tickmarks every year.</div>
<div><br>
</div>
<div> sres@vpWidthF = 0.8</div>
<div> sres@vpHeightF = 0.5</div>
<div> sres@vpXF = .15</div>
<div> sres@trYMinF = -3.5</div>
<div> sres@trYMaxF = 3.5</div>
<div> sres@gsnDraw = True</div>
<div> ;sres@gsnFrame = False</div>
<div> sres@gsnXYBarChart = True</div>
<div> sres@gsnXYBarChartBarWidth = 0.20 ; change bar widths</div>
<div> sres@tmXBMode = "Explicit" ; explicit labels</div>
<div> sres@tmXBLabelFontHeightF = 0.0205</div>
<div> sres@tmXTLabelFontHeightF = 0.0205</div>
<div> sres@tmYLLabelFontHeightF = 0.0225</div>
<div> sres@tiMainFontHeightF = 0.025</div>
<div> sres@tiMainFont = "helvetica"</div>
<div> sres@tiMainString = "Precipitation Anomalies for Mpwapwa"</div>
<div> sres@gsnRightString = ""</div>
<div> sres@tiYAxisString = "Pr Anomalies (mm/day) DJFMA"</div>
<div> sres@gsnYRefLine = 0. ; reference line </div>
<div> </div>
<div> do hh = 0,33</div>
<div> stdarr(hh,0) = (/ (yIndex(hh::34)) /)</div>
<div> </div>
<div> if ((hh.eq.1) .or. (hh.eq.2) .or. (hh.eq.3)) then</div>
<div>sres@gsnXYBarChartColors = (/"pink"/) </div>
<div>else </div>
<div>sres@gsnXYBarChartColors = (/"red"/) </div>
<div>end if</div>
<div> plot1 = gsn_csm_xy(wks,fspan(1855.6,1888.7,34),stdarr(hh,0),sres) ; draw each time series</div>
<div><br>
</div>
<div> end do</div>
<div><br>
</div>
<div><br>
</div>
<div> sres@gsnXYBarChartColors = (/"black"/) ; seperately, not</div>
<div> plot2 = gsn_csm_xy(wks,fspan(1855.8,1888.9,34),stdarr(:,1),sres) ; advancing the frame</div>
<div> sres@gsnXYBarChartColors = (/"blue"/) ; drawn on the X-axis</div>
<div> plot3 = gsn_csm_xy(wks,fspan(1856.4,1889.2,34),stdarr(:,2),sres) </div>
<div><br>
</div>
<div> lbres = True ; labelbar only resources</div>
<div> lbres@vpWidthF = 0.2 ; labelbar width</div>
<div> lbres@vpHeightF = 0.1 ; labelbar height</div>
<div> lbres@lbBoxMajorExtentF = 0.56 ; puts space between color boxes</div>
<div> lbres@lbMonoFillPattern = True ; Solid fill pattern</div>
<div> lbres@lbLabelFontHeightF = 0.025 ; font height. default is small</div>
<div> lbres@lbLabelJust = "CenterLeft" ; left justify labels</div>
<div> lbres@lbPerimOn = False</div>
<div> lbres@lgPerimColor = "white"</div>
<div> colors = (/"red", "black", "blue"/)</div>
<div> labels = (/"Index", "Reanalysis", "CMIP5"/)</div>
<div> xpos = (/0.15, 0.40, 0.7/)</div>
<div><br>
</div>
<div> do i=0,2</div>
<div> lbres@lbFillColors = colors(i)</div>
<div> gsn_labelbar_ndc(wks,1,labels(i),xpos(i),0.20,lbres)</div>
<div> end do</div>
<div> </div>
<div> frame(wks) </div>
<div>end</div>
<br>
</div>
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="m_2869186732328664211m_-2758451608644265370x_m_-6668778768257118678Signature">
<div>
<div style="font-family:Tahoma;font-size:13px"></div>
<div style="font-family:Tahoma;font-size:13px">
<div style="font-family:Tahoma;font-size:13px">Dr. Melissa Lazenby
<div>Lecturer in Climate Change</div>
<div>Department of Geography</div>
<div>Chichester 1 C150</div>
<div>University of Sussex</div>
<div><br>
</div>
<div><i style="color:inherit;font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit">"Education is the most powerful weapon which you can use to change the world" Nelson Mandela</i><br>
</div>
<div><i style="color:inherit;font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><br>
</i></div>
<div><i style="color:inherit;font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><img style="max-width: 100%;" src="cid:18685db63bd5b2dc94e1"><br>
</i></div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</div>
</blockquote>
</div>
</div>
</div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@mailman.ucar.edu" target="_blank">ncl-talk@mailman.ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="https://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">https://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span><font color="#888888">Adam Phillips <br></font></span></div><span><font color="#888888">Associate Scientist IV, Climate Analysis Section</font></span></div><div><span><font color="#888888">Climate and Global Dynamics Laboratory<br></font></span></div></div><div><span style="color:rgb(136,136,136)">National Center for Atmospheric Research</span><span><font color="#888888"><br></font></span></div><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a> </font></span></div><span><font color="#888888"></font></span><div><div><span><font color="#888888"><br></font></span><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank"></a></font></span></div></div></div></div></div></div></div></div></div></div></div>