;************************************************* ; bar_2.ncl ; ; Concepts illustrated: ; - Drawing bars instead of curves in an XY plot ; - Changing the aspect ratio of a bar plot ; - Drawing filled bars up or down based on a Y reference value ; - Setting the minimum/maximum value of the Y axis in a bar plot ;************************************************ ; MAIN ;************************************************ f = addfile ("SOI.nc", "r") ; add file date = f->time ; YYYYMM dsoi = f->SOI_DARWIN ; Darwin SOI ;---Trenberth's 11-point smoother effectively removes fluctuations ; with periods of less than 8 months but includes all others. ; At 24 months 80% of the variance is retained. ; Use reflective boundaries (kopt) to fill out plot kopt = 1 wgtk = (/ 0.0270, 0.05856, 0.09030, 0.11742, 0.13567, \ 0.1421, 0.13567, 0.11742, 0.09030, 0.05856, 0.027 /) dsoik = wgt_runave_n_Wrap (dsoi, wgtk, kopt, 0) printVarSummary(dsoik) printMinMax(dsoik,0) ;---Decadal filetr ihp = 0 ; low_pass sigma = 1.0 ; Lanczos sigma nWgt = 121 ; loose 60 (nWgt/2) months each end fca = 1./120. ; decadal wgtd = filwgts_lanczos (nWgt, ihp, fca, -999., sigma ) dsoid = wgt_runave_n_Wrap ( dsoi, wgtd, 0, 0 ) ; 10 year printVarSummary(dsoid) printMinMax(dsoid,0) ; convert integer YYYYMM to float dateF = yyyymm_to_yyyyfrac(date,0) ;********************************* ; create plot ;K******************************** wks = gsn_open_wks ("png", "bar" ) ; send graphics to PNG file res = True res@gsnScale = True ; these four resources allow the user to stretch the plot size, and ; decide exactly where on the page to draw it. ; res@vpXF = 0.10 ; In page coordinates, where to start ; res@vpYF = 0.75 ; the plot res@vpHeightF = 0.43 ; Changes the aspect ratio res@vpWidthF = 0.85 res@gsnMaximize = True res@tiYAxisString = "Anomalies" ; y-axis label res@tiXAxisString = "" res@gsnYRefLine = 0. ; reference line res@gsnXYBarChart = True ; create bar chart res@gsnAboveYRefLineColor = "red" ; above ref line fill red res@gsnBelowYRefLineColor = "blue" ; below ref line fill blue ; array syntax (::8) to plot every 8th value to demonstrate 'bar' res@trYMinF = -3.0 ; min value on y-axis res@trYMaxF = 3.0 ; max value on y-axis res@tiMainString = "Darwin SOI: Trenberth 11pt: Every 8th value" ; title plot = gsn_csm_xy (wks,dateF(::8),dsoik(::8),res) ; every 8-th value ;++++++++++++ res@gsnXYBarChart = False ; turn-off bar chart; plot standard x-y; all values res@trYMinF = -2.0 ; min value on y-axis res@trYMaxF = 2.0 ; max value on y-axis res@tiMainString = "Darwin SOI: Trenberth 11-pt" ; title plot = gsn_csm_xy (wks,dateF,dsoik,res) ; all values ;++++++++++++ res@trYMinF = -1.0 ; min value on y-axis res@trYMaxF = 1.0 ; max value on y-axis res@tiMainString = "Darwin SOI: Decadal: nWgt="+nWgt ; title plot = gsn_csm_xy (wks,dateF,dsoid,res) ; all values