load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" begin npts = 12 nplots = 4 stdarr = random_uniform(0.1,1.15,(/nplots,npts/)) ; ; Define the x values for each set of bars to be slightly shifted ; so the bars don't overlap. The bars are shifted by 0.15 each ; which is what we'll use for the bar width later. ; ii = ispan(0,npts-1,1) bar_width = 0.15 xarr = new((/nplots,npts/),float) do i=0,nplots-1 xarr(i,:) = ii+0.775 + (i*bar_width) end do colors = (/"red","lightblue","blue","forestgreen"/) wks = gsn_open_wks("png","bar") sres = True sres@gsnDraw = False sres@gsnFrame = False sres@vpWidthF = 0.7 sres@vpHeightF = 0.5 sres@trXMinF = min(xarr)-0.5 ; Leave some space before sres@trXMaxF = max(xarr)+0.5 ; and after bars. sres@trYMinF = 0.0 sres@trYMaxF = max(stdarr)+.1 ; Leave some space at top sres@gsnXYBarChart = True sres@gsnXYBarChartBarWidth = bar_width ; make bar width smaller, otherwise ; they will overlap sres@tmXBMode = "Explicit" ; explicit labels sres@tmXBValues = ispan(1,12,1) sres@tmXBLabels = (/"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", \ "Oct","Nov","Dec"/) sres@tmXBLabelFontHeightF = 0.0205 sres@tmXTLabelFontHeightF = 0.0205 sres@tmYLLabelFontHeightF = 0.0225 sres@gsnRightString = "" sres@tiYAxisString = "(~S~o~N~C)" ; ; Loop through each plot, create it, and then overlay ; subsequent ones one the first one. ; plots = new(nplots,graphic) do i=0,nplots-1 sres@gsnXYBarChartColors = colors(i) plots(i) = gsn_csm_xy(wks,xarr(i,:),stdarr(i,:),sres) if(i.gt.0) then overlay(plots(0),plots(i)) end if end do ;---Drawing plots(0) will also draw all the overlaid plots. draw(plots(0)) ;---Draw a legend at the bottom lbres = True ; labelbar only resources lbres@vpWidthF = 0.2 ; labelbar width lbres@vpHeightF = 0.1 ; labelbar height lbres@lbBoxMajorExtentF = 0.15 ; puts space between color boxes lbres@lbMonoFillPattern = True ; Solid fill pattern lbres@lbLabelFontHeightF = 0.015 ; font height. default is small lbres@lbLabelJust = "CenterLeft" ; left justify labels lbres@lbPerimOn = False labels = (/"first", "second", "third", "fourth"/) xpos = (/0.05, 0.3, 0.55, 0.8/) do i=0,3 lbres@lbFillColors = colors(i) gsn_labelbar_ndc(wks,1,labels(i),xpos(i),0.25,lbres) end do frame(wks) ; Advance the frame. end