<div dir="ltr">Hi Melissa,<div>I think there are two things going on.</div><div>1- Your input x-axis values (= your x array) go up by 1 for every month of the year, and then jump by 89. This will result in large blank areas in the plot as NCL will allocate space for (say) 185513-185600. The solution is to create a new x-axis array after you've defined x:</div><div>x_alt = ispan(0,dimsizes(x)-1,1)</div><div><br></div><div>manually set the x-axis tick marks and labels (to show say every 5th year):</div><div>res@tmXBLabelMode = "ExplicitLabels"</div><div>res@tmXBValues = x_alt(0::60). ; create x-axis tick mark every 5 years</div><div>res@tmXBLabels = x(0::60) ; and label them appropriately</div><div>res@tmXBMinorValues = x_alt(0::6) create minor tick marks every 6 months; optional</div><div><br></div><div>and then pass in your x_alt array as the x-axis values to plot against your y array:</div><div>plot=gsn_csm_xy(wks,x_alt,y,res)<br></div><div><br></div><div>2 - I would reset your bar width to be set to 1, or, if you don't want successive month bars touching then set it to say 0.8:</div><div>res@gsnXYBarChartBarWidth = 0.8<br></div><div><br></div><div>If you have any further questions on this please respond to ncl-talk.</div><div>Best,</div><div>Adam</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, May 10, 2023 at 9:52 AM Melissa Lazenby via ncl-talk <<a href="mailto:ncl-talk@mailman.ucar.edu">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 class="msg7738784004234071966">




<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Dear NCL Users</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I am trying to plot a bar chart with year and months on the X-axis and am struggling to do so correctly.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
I would also like to choose some years and months to be grey instead of black to show certainty levels. I am trying to make a similar plot to the one below:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<img style="max-width: 100%;" size="24966" src="cid:1880d1f6fb6cb971f162"><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
This is what I currently have:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<img style="max-width: 100%;" size="64237" src="cid:1880d1f6fb6cb971f161"><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Any help would be greatly appreciated!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Kindest Regards</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Melissa</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
Code:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<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>;************************************************</div>
<div>begin</div>
<div> </div>
<div>;************************************************</div>
<div>; plotting</div>
<div>;************************************************</div>
<div>  wks  = gsn_open_wks("X11","Mpwapwa_Index")                </div>
<div>  </div>
<div>  res                          = True </div>
<div>  res@gsnMaximize              = True</div>
<div>  res@tiXAxisString             = "Year & Month"       ; x-axis label</div>
<div>  res@tiYAxisString             = "Precipitation Index"     ; y-axis label</div>
<div>  res@gsnXYBarChart = True</div>
<div>  res@gsnXYBarChartBarWidth = 0.1</div>
<div>  res@gsnYRefLine           = 0             ; reference line  
</div>
<div>  res@tiMainString = "Mpwapwa"</div>
<div>    </div>
<div>  res@trYMinF                   =  -3.5           ; min level</div>
<div>  res@trYMaxF                   =  3.5            ; max level</div>
<div>   </div>
<div>  res@vpWidthF            = 1.5         ; Make the plot wider than it
</div>
<div>  res@vpHeightF           = 0.75        ; is high.</div>
<div><br>
</div>
<div>  res@gsnDraw             = False              ; do not draw the plot</div>
<div>  res@gsnFrame            = False  </div>
<div> </div>
<div>;Years and Months  </div>
<div>x = (/185501,     185502,     185503,     185504,     185505,     185506,     185507,     185508,     185509,     185510,     185511,     185512,     185601,     185602,     185603,     185604,     185605,     185606,     185607,     185608,     185609,     185610,     185611,     185612,     185701,     185702,     185703,     185704,     185705,     185706,     185707,     185708,     185709,     185710,     185711,     185712,     185801,     185802,     185803,     185804,     185805,     185806,     185807,     185808,     185809,     185810,     185811,     185812,     185901,     185902,     185903,     185904,     185905,     185906,     185907,     185908,     185909,     185910,     185911,     185912,     186001,     186002,     186003,     186004,     186005,     186006,     186007,     186008,     186009,     186010,     186011,     186012,     186101,     186102,     186103,     186104,     186105,     186106,     186107,     186108,     186109,     186110,     186111,     186112,     186201,     186202,     186203,     186204,     186205,     186206,     186207,     186208,     186209,     186210,     186211,     186212,     186301,     186302,     186303,     186304,     186305,     186306,     186307,     186308,     186309,     186310,     186311,     186312,     186401,     186402,     186403,     186404,     186405,     186406,     186407,     186408,     186409,     186410,     186411,     186412,     186501,     186502,     186503,     186504,     186505,     186506,     186507,     186508,     186509,     186510,     186511,     186512,     186601,     186602,     186603,     186604,     186605,     186606,     186607,     186608,     186609,     186610,     186611,     186612,     186701,     186702,     186703,     186704,     186705,     186706,     186707,     186708,     186709,     186710,     186711,     186712,     186801,     186802,     186803,     186804,     186805,     186806,     186807,     186808,     186809,     186810,     186811,     186812,     186901,     186902,     186903,     186904,     186905,     186906,     186907,     186908,     186909,     186910,     186911,     186912,     187001,     187002,     187003,     187004,     187005,     187006,     187007,     187008,     187009,     187010,     187011,     187012,     187101,     187102,     187103,     187104,     187105,     187106,     187107,     187108,     187109,     187110,     187111,     187112,     187201,     187202,     187203,     187204,     187205,     187206,     187207,     187208,     187209,     187210,     187211,     187212,     187301,     187302,     187303,     187304,     187305,     187306,     187307,     187308,     187309,     187310,     187311,     187312,     187401,     187402,     187403,     187404,     187405,     187406,     187407,     187408,     187409,     187410,     187411,     187412,     187501,     187502,     187503,     187504,     187505,     187506,     187507,     187508,     187509,     187510,     187511,     187512,     187601,     187602,     187603,     187604,     187605,     187606,     187607,     187608,     187609,     187610,     187611,     187612,     187701,     187702,     187703,     187704,     187705,     187706,     187707,     187708,     187709,     187710,     187711,     187712,     187801,     187802,     187803,     187804,     187805,     187806,     187807,     187808,     187809,     187810,     187811,     187812,     187901,     187902,     187903,     187904,     187905,     187906,     187907,     187908,     187909,     187910,     187911,     187912,     188001,     188002,     188003,     188004,     188005,     188006,     188007,     188008,     188009,     188010,     188011,     188012,     188101,     188102,     188103,     188104,     188105,     188106,     188107,     188108,     188109,     188110,     188111,     188112,     188201,     188202,     188203,     188204,     188205,     188206,     188207,     188208,     188209,     188210,     188211,     188212,     188301,     188302,     188303,     188304,     188305,     188306,     188307,     188308,     188309,     188310,     188311,     188312,     188401,     188402,     188403,     188404,     188405,     188406,     188407,     188408,     188409,     188410,     188411,     188412,     188501,     188502,     188503,     188504,     188505,     188506,     188507,     188508,     188509,     188510,     188511,     188512,     188601,     188602,     188603,     188604,     188605,     188606,     188607,     188608,     188609,     188610,     188611,     188612,     188701,     188702,     188703,     188704,     188705,     188706,     188707,     188708,     188709,     188710,     188711,     188712,     188801,     188802,     188803,     188804,     188805,     188806,     188807,     188808,     188809,     188810,     188811,     188812,     188901,     188902,     188903,     188904,     188905,     188906,     188907,     188908,     188909,     188910,     188911,     188912,     189001,     189002,     189003,     189004,     189005,     189006,     189007,     189008,     189009,     189010,     189011,     189012/)</div>
<div><br>
</div>
<div>;Index</div>
<div>y = (/ 0,   0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    3,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    -1,   0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    -3,   -3,   -3,   -3,   0,    0,    0,    0,    0,    0,    0,    0,    2,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0.05, 0,    0,    0,    0,    0,    0,    2,    1,    1,    1,    1,    1,    2,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    -1,   1,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    -1,   -1,   -1,   -1,   -1,   0,    0,    0,    0,    0,    0,    0,    -2,   -2,   -2,   -2,   -2,   0,    0,    0,    0,    0,    0,    1,    1,    1,    1,    1,    1,    0.05, 0,    0,    0,    0,    1,    0.05, 0.05, 0.05, 0.05, 0.05, 2,    0,    0,    0,    0,    0,    0,    0,    -1,   -2,   -3,   -2,   -2,   0,    0,    0,    0,    0,    0,    0,    -2,   0,    -1,   0,    0,    0,    0,    0,    0,    0,    0,    2,    1,    0.05, 1,    0.05, 0.05, 0.05, 0,    0,    0,    0,    0,    0,    -1,   -1,   0.05, 0.05, 0,    0,    0,    0,    0,    0,    0,    0,    -3,   0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0.05, 0.05, 0.05, 0.05, 0.05, 0,    0,    0,    0,    0,    0,    0,    0.05, 0.05, 0.05, 0.05, 0.05, 0,    0,    0,    0,    0,    0,    0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0,    0,    0,    0,    0,    0,    0,    -2,   -3,   -3,   -3,   -2,   0,    0,    0,    0,    0,    0.05, 0,    0.05, 0.05, 0.05, 0.05, 0.05, 0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0/)</div>
<div><br>
</div>
<div> res@tmXBMode        = "Manual"     </div>
<div>  res@tmXBTickStartF  = 185501</div>
<div>  res@tmXBTickEndF    = 189012</div>
<div>  ;res@tmXBTickSpacingF= 120</div>
<div>  res@tmXBLabelStride = 1</div>
<div><br>
</div>
<div><br>
</div>
<div> bc = new(432,string)</div>
<div> bc= "black"</div>
<div>time = (/185501,185502,185503,      185504,     185505,     185506,     185507,     185508,     185509,     185510,     185511,     185512,     185601,     185602,     185603,     185604,     185605,     185606,     185607,     185608,     185609,     185610,     185611,     185612,     185701,     185702,     185703,     185704,     185705,     185706,     185707,     185708,     185709,     185710,     185711,     185712,     185801,     185802,     185803,     185804,     185805,     185806,     185807,     185808,     185809,     185810,     185811,     185812,     185901,     185902,     185903,     185904,     185905,     185906,     185907,     185908,     185909,     185910,     185911,     185912,     186001,     186002,     186003,     186004,     186005,     186006,     186007,     186008,     186009,     186010,     186011,     186012,     186101,     186102,     186103,     186104,     186105,     186106,     186107,     186108,     186109,     186110,     186111,     186112,     186201,     186202,     186203,     186204,     186205,     186206,     186207,     186208,     186209,     186210,     186211,     186212,     186301,     186302,     186303,     186304,     186305,     186306,     186307,     186308,     186309,     186310,     186311,     186312,     186401,     186402,     186403,     186404,     186405,     186406,     186407,     186408,     186409,     186410,     186411,     186412,     186501,     186502,     186503,     186504,     186505,     186506,     186507,     186508,     186509,     186510,     186511,     186512,     186601,     186602,     186603,     186604,     186605,     186606,     186607,     186608,     186609,     186610,     186611,     186612,     186701,     186702,     186703,     186704,     186705,     186706,     186707,     186708,     186709,     186710,     186711,     186712,     186801,     186802,     186803,     186804,     186805,     186806,     186807,     186808,     186809,     186810,     186811,     186812,     186901,     186902,     186903,     186904,     186905,     186906,     186907,     186908,     186909,     186910,     186911,     186912,     187001,     187002,     187003,     187004,     187005,     187006,     187007,     187008,     187009,     187010,     187011,     187012,     187101,     187102,     187103,     187104,     187105,     187106,     187107,     187108,     187109,     187110,     187111,     187112,     187201,     187202,     187203,     187204,     187205,     187206,     187207,     187208,     187209,     187210,     187211,     187212,     187301,     187302,     187303,     187304,     187305,     187306,     187307,     187308,     187309,     187310,     187311,     187312,     187401,     187402,     187403,     187404,     187405,     187406,     187407,     187408,     187409,     187410,     187411,     187412,     187501,     187502,     187503,     187504,     187505,     187506,     187507,     187508,     187509,     187510,     187511,     187512,     187601,     187602,     187603,     187604,     187605,     187606,     187607,     187608,     187609,     187610,     187611,     187612,     187701,     187702,     187703,     187704,     187705,     187706,     187707,     187708,     187709,     187710,     187711,     187712,     187801,     187802,     187803,     187804,     187805,     187806,     187807,     187808,     187809,     187810,     187811,     187812,     187901,     187902,     187903,     187904,     187905,     187906,     187907,     187908,     187909,     187910,     187911,     187912,     188001,     188002,     188003,     188004,     188005,     188006,     188007,     188008,     188009,     188010,     188011,     188012,     188101,     188102,     188103,     188104,     188105,     188106,     188107,     188108,     188109,     188110,     188111,     188112,     188201,     188202,     188203,     188204,     188205,     188206,     188207,     188208,     188209,     188210,     188211,     188212,     188301,     188302,     188303,     188304,     188305,     188306,     188307,     188308,     188309,     188310,     188311,     188312,     188401,     188402,     188403,     188404,     188405,     188406,     188407,     188408,     188409,     188410,     188411,     188412,     188501,     188502,     188503,     188504,     188505,     188506,     188507,     188508,     188509,     188510,     188511,     188512,     188601,     188602,     188603,     188604,     188605,     188606,     188607,     188608,     188609,     188610,     188611,     188612,     188701,     188702,     188703,     188704,     188705,     188706,     188707,     188708,     188709,     188710,     188711,     188712,     188801,     188802,     188803,     188804,     188805,     188806,     188807,     188808,     188809,     188810,     188811,     188812,     188901,     188902,     188903,     188904,     188905,     188906,     188907,     188908,     188909,     188910,     188911,     188912,     189001,     189002,     189003,     189004,     189005,     189006,     189007,     189008,     189009,     189010,     189011,     189012/)</div>
<div><br>
</div>
<div>selyr = (/185709,185812,185912,186001, 186002,18603,186012, 187105,187211,187412,187506,187601,188001,188102,188204/)
</div>
<div>do gg = 0,dimsizes(selyr)-1</div>
<div>     bc = where(time.eq.selyr(gg),"grey",bc)  </div>
<div> end do</div>
<div><br>
</div>
<div> res@gsnXYBarChartColors = "bc" </div>
<div><br>
</div>
<div>      </div>
<div>plot=gsn_csm_xy(wks,x,y,res)</div>
<div><br>
</div>
<div> draw(plot)</div>
<div> frame(wks)</div>
<div><br>
</div>
<div>end</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<br>
</div>
<div><br>
</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_7738784004234071966Signature">
<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="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="font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><br>
</i></div>
<div><i style="font-family:inherit;font-size:inherit;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inherit"><img style="max-width: 100%;" src="cid:1880d1f6fb6959b3a2c3"><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><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><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>