; https://www.ncl.ucar.edu/Support/talk_archives/2013/3871.html (x lable) ; https://www.ncl.ucar.edu/Applications/Scripts/xy_7.ncl ; https://www.ncl.ucar.edu/Applications/xy.shtml (xy_25.ncl) ;**************************************************** ; xy_7.ncl ; ; Concepts illustrated: ; - Drawing an XY plot with two different Y axes ; - Changing the title on the Y axis ; - Changing the line dash pattern in an XY plot ; - Changing the line color for multiple curves in an XY plot ; - Setting the mininum/maximum value of the Y axis in an XY plot ; ;**************************************************** ; ; 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" ;**************************************************** begin ;*************************** ; read in data ;*************************** data_col = asciiread("data.txt",31,"string") delim = " " date = str_get_field(data_col(1:),1,delim) prec = tofloat(str_get_field(data_col(1:),2,delim)) sm = tofloat(str_get_field(data_col(1:),3,delim)) ; sm@_FillValue = 9999 ;*************************** ; plot parameters ;*************************** wks = gsn_open_wks ("png","GPM_SMAP_20170401_30") ; send graphics to PNG file ; resources for "left" variable resL = True resL@gsnMaximize = True resL@vpWidthF = 0.8 ; Change the aspect ratio, but resL@vpHeightF = 0.4 ; make plot as large as possible. resL@trYMaxF = max(prec)+1 ; axis max resL@trYMinF = min(prec) ; axis min resL@xyLineThicknessF = 2. ; thicker line resL@xyLineColor = "blue" ; line color resL@tiYAxisFontColor = resL@xyLineColor resL@tiYAxisString = "Precipitation (mm/day)" ; axis string resL@tiMainString = "Precipitation and Soil Moisture" ; title ; resources for "right" variable resR = True resR@trYMaxF = max(sm) ; axis max resR@trYMinF = min(sm) ; axis min resR@xyDashPatterns = 2 ; dashed line for 2nd resR@xyLineThicknessF = 2 ; thicker line resR@xyLineColor = "red" ; line color resR@tiYAxisFontColor = resR@xyLineColor ; resR@tmYRFormat = "f" ; Remove trailing zeros from labels resR@tiYAxisString = "Soil Moisture (cm~S~3~N~/cm~S~3~N~)" ; axis string resL@tmXBMode = "Explicit" ; explicit labels resL@tmXBValues = ispan(0,dimsizes(date)-1,1) resL@tmXBLabels = date plot = gsn_csm_xy2(wks,ispan(0,dimsizes(date)-1,1),prec,sm,resL,resR) end