;XY overlay
;----------------------------------------------------------------------
; xy_32.ncl
;
; Concepts illustrated:
; - Drawing a time series plot
; - Drawing multiple legends outside an XY plot
; - Overlaying XY plots on each other
; - Changing the labels in a legend
; - Labeling the X axis with nicely-formatted time labels
;----------------------------------------------------------------------
; In order to have the legends side-by-side, instead of one legend
; with 8 lines it in, it is necessary to create 4 XY plots, each with
; its own legend. Each legend is moved to the right or left
; slightly so they don't overlap. The plots are all "connected" into
; one plot using "overlay".
;----------------------------------------------------------------------
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/contrib/time_axis_labels.ncl"
begin
dir = "$NCARG_ROOT/lib/ncarg/data/cdf/"
a = addfile(dir + "chi200_ud_smooth.nc","r")
chi = transpose(a->CHI)
chi = chi/1.e6 ; scale for convenience
;---Start the graphics
wks = gsn_open_wks("ps","xy")
;---Plotting options for time series plot
res = True
res@gsnMaximize = True
res@gsnDraw = False ; Will draw later, after overlaying
res@gsnFrame = False ; all plots
res@vpWidthF = 0.8 ; Make plots wider
res@vpHeightF = 0.4
res@trXMinF = min(chi&time)
res@trXMaxF = max(chi&time)
res@trYMinF = min(chi)
res@trYMaxF = max(chi)
;---Resources for legend
res@pmLegendDisplayMode = "Always" ; turn on legend
res@pmLegendWidthF = 0.12 ; Change width and
res@pmLegendHeightF = 0.15 ; height of legend.
res@pmLegendOrthogonalPosF = -0.08 ; move up slightly
res@lgLabelFontHeightF = .011 ; change font height
res@lgPerimOn = False ; no box around
res@lgItemOrder = (/1,0/) ; reverse legend
;---Titles
res@tiMainString = chi@long_name
res@tiYAxisString = ""
;---Turn off some tickmarks
res@tmXTOn = False ; bottom off
res@tmYROn = False ; right off
res@xyLineThicknessF = 2.0 ; default is 1
res@xyMonoDashPattern = True ; force all solid lines
;--------------------------------------------------
; The time_axis_label function adds additional
; resources to "res" to produce nicely-formatted
; time labels on X axis. This function only works
; if you have a time "units" recognized by the
; cd_calendar function.
;---------------------------------------------------
restick = True
restick@ttmFormat = "%N/%D/%y"
time_axis_labels(chi&time,res,restick)
;---Subset of longitudes to plot for the four plots
lon1_start_idx = 0
lon1_end_idx = 1
;---Set resources for colors and labels
colors1 = (/"blue","red"/)
labels4 = "lon = " + chi&lon(lon4_start_idx:lon4_end_idx)
;---Create the four XY plots
res@xyLineColors = colors1
res@xyExplicitLegendLabels = labels1
res@pmLegendParallelPosF = 0.15
plot1 = gsn_csm_xy(wks,chi&time,chi(lon1_start_idx:lon1_end_idx,:),res)
;---Overlay one plot on the other, so they become one plot.
overlay(plot1,plot2)
overlay(plot1,plot3)
overlay(plot1,plot4)
draw(plot1) ; This will draw all four plots
frame(wks)
end
;CONTOUR overlay
;-----------------------------------------------------------------------------------------
plot = gsn_csm_contour_map_overlay(wks,temp,uwnd,res,sres) ; create the overlay plot
;--------------------------
wks = gsn_open_wks("ps","overlay")
res@gsnFrame = False ; do not advance the frame
;Create individual plotsand use overlay to combine them
plot = gsn_csm_contour_map(wks,temp,res) ; create the temperature plot
plot_ov = gsn_csm_contour(wks,uwnd,sres) ; create the U-wind plot
overlay(plot,plot_ov) ; overlay the U-wind plot on the temperature plot
draw(plot) ; draw the temperature plot (with the U-wind plot overlaid)
frame(wks) ; advance the frame
;-----------------
;Overlaying plots manually by not advancing the frame
res@gsnFrame = False ; do not advance the frame
plot = gsn_csm_contour_map(wks,temp,res) ; create and draw the temperature plot
plot2 = gsn_csm_contour_map(wks,uwnd,sres) ; create and draw the U-wind plot on top of the temperature plot
frame(wks) ; advance the frame