; =============================================== ; bar_horz_5.ncl ; ; Concepts illustrated: ; - Drawing multiple sets of filled bars left or right based on multiple X reference values ; - Drawing bars instead of curves in an XY plot ; - Changing the aspect ratio of a bar plot ; - Setting the minimum/maximum value of the X axis in a bar plot ; - Changing the labels and tickmarks in a bar plot ; - Adding labels to the bottom X axis ; ; =============================================== ; ; 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" ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; ; This file still has to be loaded manually load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl" begin fili = "Jsst.nc" f = addfile (fili , "r") time = f->time date = f->date sst = f->SST sst = (/ sst /)*0.1 ; scale sst anomalies wgt = (/ 1., 2., 1./) wgt = wgt/sum(wgt) sst = wgt_runave (sst, wgt, 0) warm = (/1951,1953,1957,1963,1965,1969 \ ; warm years , 1972,1976,1982,1987,1991 /) nWarm = dimsizes(warm) ; number of curves nMonth= 37 month = fspan(0., 36., 37) month@long_name = "Month" data = new( (/nWarm,nMonth/), float) ; make one array for ; multiple lines ;Please note: we have found that running other SST data through this ;script resulted in a 1-year offset. To compensate for this, we ;added the line:indStrt = indStrt-12 to the loop. do nW=0,nWarm-1 ; Fill each 37 month segment indStrt = ind(date.eq.warm(nW)*100+01) indLast = indStrt+nMonth-1 data(nW,:) = sst(indStrt:indLast) end do ;---------------------------------- ; create plot ;---------------------------------- wks = gsn_open_wks ("png", "bar_horz" ) ; send graphics to PNG file res = True res@trXMinF = -2.0 ; bottom of X-scale res@trXMaxF = 2.0 ; nominal top of X-scale tickMark = 1.0 ; tick Mark increment (1 degree) curv_offset = res@trXMaxF-res@trXMinF ; range res@trXMaxF = curv_offset*nWarm + res@trXMinF + tickMark do nW=0,nWarm-1 data(nW,:) = data(nW,:) + curv_offset*nW end do res@xyMonoDashPattern = True ; all solid lines res@tmXBLabelFontHeightF = 0.01 ; default is 0.02 res@tmXBMode = "Explicit" ; Define own bottom tick mark labels. res@tmXBValues = fspan(res@trXMinF,res@trXMaxF,floattointeger((res@trXMaxF-res@trXMinF)/tickMark)+1 ) res@tmXUseBottom = False res@tmXTLabelsOn = True res@tmXTMode = "Explicit" ; Define own top tick mark labels. res@tmXTValues = res@tmXBValues res@tmXTLabelFontHeightF = res@tmXBLabelFontHeightF res@tmXBLabels = (/" ","-1","0","1" \ ; left labels ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" \ ," ","-1","0","1" ," "," "/) res@tmXTLabels = (/" ","","1951","" \ ; right labels ," ","","1953","" \ ," ","","1957","" \ ," ","","1963","" \ ," ","","1965","" \ ," ","","1969","" \ ," ","","1972","" \ ," ","","1976","" \ ," ","","1982","" \ ," ","","1987","" \ ," ","","1991","" ," "," "/) res@tiYAxisString = "Warm Events ~N~(~S~o~N~C)" res@tiYAxisFontHeightF = 0.018 res@tiMainString = "Monthly SST Anomalies for Nino-3" res@gsnXRefLine = res@trXMinF + 0.5*curv_offset + ispan(0,nWarm-1,1)*curv_offset res@gsnRightXRefLineColor = "Red" res@gsnLeftXRefLineColor = "Blue" res@tmYLMode = "Explicit" ; Define own tick mark labels. res@tmYLValues = (/ 0. , 6. , 12., 18., 24., 30., 36./) ; note, if the text of your plot looks exactly like listed below, then ; you do not have the correct function code a ~ in your .hluresfile. ; Don't know what a .hluresfile is? See the main page of the graphics ; web site for details. res@tmYLLabels = (/"Jan~B~-1~N~","Jul~B~-1~N~","Jan~B~0~N~","Jul~B~0~N~",\ "Jan~B~+1~N~","Jul~B~+1~N~","Jan~B~+2~N~"/) res@gsnXYBarChart = True plot = gsn_csm_xy (wks,data(0:nWarm-1,:),month,res) end