<div dir="ltr"><div><div>Hi,<br><br>I am trying to plot two bar plots in one common plot<br></div>Here is the code. The error is gsn_open_wks is undefined. How do I approach this problem.<br></div>Thank you in advance<br><div>
<div><br><br>;Trend and monthly Climatology together<br>;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br><br>months=(/1,2,3,4,5,6,7,8,9,10,11,12/)<br>
x=asciiread("~/Documents/PhD_June_2015/NCL_Moonsoon/Data_output/Trend_monthly.txt",(/12,2/), "float")<br><br>print(x)<br><br>begin<br> npts = 12<br> nplots = 2<br> <br>;<br>; Define the x values for each set of bars to be slightly shifted<br>
; so the bars don't overlap. The bars are shifted by 0.15 each<br>; which is what we'll use for the bar width later.<br>;<br> ii = ispan(0,npts-1,1)<br> bar_width = 0.15<br> xarr = new((/nplots,npts/),float)<br>
do i=0,nplots-1<br> xarr(i,:) = ii+0.775 + (i*bar_width)<br> end do<br><br> colors = (/"red","lightblue"/)<br> wks=gsn_open_wks("png","bar")<br><br>
sres = True<br> sres@gsnDraw = False<br> sres@gsnFrame = False<br><br> sres@vpWidthF = 0.7<br> sres@vpHeightF = 0.5<br><br> sres@trXMinF = min(xarr)-0.5 ; Leave some space before<br>
sres@trXMaxF = max(xarr)+0.5 ; and after bars.<br> sres@trYMinF = 0.0<br> sres@trYMaxF = max(stdarr)+.1 ; Leave some space at top<br><br> sres@gsnXYBarChart = True<br>
sres@gsnXYBarChartBarWidth = bar_width ; make bar width smaller, otherwise<br> ; they will overlap<br><br> sres@tmXBMode = "Explicit" ; explicit labels<br>
sres@tmXBValues = ispan(1,12,1)<br> sres@tmXBLabels = (/"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", \<br>
"Oct","Nov","Dec"/)<br><br> sres@tmXBLabelFontHeightF = 0.0205<br> sres@tmXTLabelFontHeightF = 0.0205<br> sres@tmYLLabelFontHeightF = 0.0225<br>
<br> sres@gsnRightString = ""<br> sres@tiYAxisString = "Precipitation in mm"<br> <br>;<br>; Loop through each plot, create it, and then overlay<br>; subsequent ones one the first one.<br>
;<br> plots = new(nplots,graphic)<br> do i=0,1<br> sres@gsnXYBarChartColors = colors(i)<br> plots(i) = gsn_csm_xy(wks,xarr(i,:),x(:,i),sres)<br><br> if(i.gt.0) then<br> overlay(plots(0),plots(i))<br>
end if<br> end do<br><br>;---Drawing plots(0) will also draw all the overlaid plots.<br> draw(plots(0))<br><br><br> frame(wks) ; Advance the frame.<br>end<br></div></div></div>