; xy_23.ncl
;
; Concepts illustrated:
; - Attaching multiple XY plots along the X axes
; - Turning off tickmarks on the left Y axis
; - Turning on tickmarks on the right Y axis
; - Moving tickmark labels away from axis
;
;*****************************************************
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
;*****************************************************
;
; This example illustrates the creation of a set of 4
; of 'stacked' XY plots. Each plot has the same X axis.
; By using gsn_attach_plots, all four plots can be
; manipulated as a unit through the base plot.
;
; To demonstrate this concept, the base plot is resized
; in the second frame.
;
; Each plot draws a variation of sinusoidal curve.
;
begin
;
; Define the number of points in each curve.
;
NPTS = 500
PI100 = 0.031415926535898
EXP = 2.7182818
;
; Create data for the four XY plots.
;
theta = PI100*ispan(0,NPTS-1,1)
y1 = sin(theta)+1
y2 = sin(theta * theta)+1
y3 = sin(EXP^theta)+1
y4 = sin(3*sqrt(fabs(theta)))+1
;***Sharon added three more sets of data
y5 = sin(theta * theta)+1
y6 = sin(EXP^theta)+1
y7 = 10*sin(3*sqrt(fabs(theta)))+40
;***
wks = gsn_open_wks("png","xy")
res = True
res@gsnMaximize = False
res@gsnDraw = False
res@gsnFrame = False
res@vpWidthF = 0.8 ; Make plots wider than
res@vpHeightF = 0.2 ; they are high.
res@tmYUseLeft = False ; Make right axis independent of left
res@tmYLOn = False ; Turn off left tickmarks
res@tmYROn = True ; Turn on right tickmarks
res@tmXTOn = True ; Turn off top tickmarks
res@tmYLLabelsOn = False ; Turn off left labels
res@tmYRLabelsOn = True ; Turn on right labels
res@tmYRMinorOn = False ; Turn off minor ticks on Y axis
res@tmYRLabelFontHeightF = 0.015 ; Increase font height
res@tmYRLabelDeltaF = 2.0 ; Increase space b/w ticks and labels
res@tmYRLabelJust = "CenterRight" ; right-justify labels
res@xyLineThicknessF = 2.0 ; Twice as thick
;***Sharon added - but does not work, if commented out results in bottom
;*** tick label from upper graphs overlapping top label from lower graphs
; res@tmYRMode = "Explicit"
; res@tmYRValues = (/ 0, 10, 20, 30, 40, 50/)
; res@tmYRLabels = (/"0","10","20","30","40"," "/)
;***
resf = True
resf@gsnMaximize = False
resf@gsnDraw = False
resf@gsnFrame = False
resf@vpWidthF = 0.8 ; Make plots wider than
resf@vpHeightF = 0.2 ; they are high.
resf@tmYUseLeft = False ; Make right axis independent of left
resf@tmYLOn = False ; Turn off left tickmarks
resf@tmYROn = True ; Turn on right tickmarks
resf@tmXTOn = False ; Turn off top tickmarks
resf@tmYLLabelsOn = False ; Turn off left labels
resf@tmYRLabelsOn = True ; Turn on right labels
resf@tmYRMinorOn = False ; Turn off minor ticks on Y axis
resf@tmYRLabelFontHeightF = 0.015 ; Increase font height
resf@tmYRLabelDeltaF = 2.0 ; Increase space b/w ticks and labels
resf@tmYRLabelJust = "CenterRight" ; right-justify labels
resf@xyLineThicknessF = 2.0 ; Twice as thick
;***Sharon added - but does not work, if commented out results in bottom
;*** tick label from upper graphs overlapping top label from lower graphs
resf@tmYRMode = "Explicit"
resf@tmYRValues = (/ 0, 10, 20, 30, 40, 50/)
resf@tmYRLabels = (/"0","10","20","30","40"," "/)
resf@trYMinF = min(resf@tmYRValues)
resf@trYMaxF = max(resf@tmYRValues)
; Change y axis string and color for each plot.
res@tiYAxisString = "xy1"
res@xyLineColor = "Purple"
xy1 = gsn_csm_y(wks,y1,resf) ; Create the four plots.
res@tiYAxisString = "xy2"
res@xyLineColor = "Brown"
xy2 = gsn_csm_y(wks,y2,res) ; They won't be drawn yet.
res@tiYAxisString = "xy3"
res@xyLineColor = "Orange"
xy3 = gsn_csm_y(wks,y3,res)
res@tiYAxisString = "xy4"
res@xyLineColor = "ForestGreen"
xy4 = gsn_csm_y(wks,y4,res)
;*** last three added by Sharon
res@tiYAxisString = "xy5"
res@xyLineColor = "Brown"
xy5 = gsn_csm_y(wks,y5,res) ; They won't be drawn yet.
res@tiYAxisString = "xy6"
res@xyLineColor = "Orange"
xy6 = gsn_csm_y(wks,y6,res)
resf@tiYAxisOffsetXF = .0045
resf@tiYAxisString = "xy7"
resf@xyLineColor = "ForestGreen"
xy7 = gsn_csm_y(wks,y7,resf)
;***
;*****************************************************
; Manually create and attach legend - 26lines: Sharon copied in from Example xy_18.ncl
;*****************************************************
res_text = True ; text mods desired
res_text@txFontHeightF = 0.015 ; change text size
res_text@txJust = "CenterLeft" ; text justification
res_lines = True ; polyline mods desired
res_lines@gsLineDashPattern = 0. ; solid line
res_lines@gsLineThicknessF = 5. ; line thicker
res_lines@gsLineColor = "red" ; line color
xx = (/93,107/)
yy = (/30.,30./)
dum1 = gsn_add_polyline(wks,xy1,xx,yy,res_lines) ; add polyline
dum2 = gsn_add_text(wks,xy1,"Anthropogenic + Natural",110,30.,res_text); add text
yy = (/22,22/)
res_lines@gsLineColor = "blue" ; change to blue
dum3 = gsn_add_polyline(wks,xy1,xx,yy,res_lines) ; add polyline
dum4 = gsn_add_text(wks,xy1,"Natural",110,22,res_text) ; add text
yy = (/26,26/)
res_lines@gsLineColor = "black" ; change to black
dum5 = gsn_add_polyline(wks,xy1,xx,yy,res_lines) ; add polyline
dum6 = gsn_add_text(wks,xy1,"Observations",110,26,res_text) ; add text
;***********************************************************
; Set up resource lists for attaching the plot.
; The res1 will apply to the base plot, and the
; res2 to the plots being attached. These resources
; lists are *not* for changing things like line color,
; but for changing things like whether the plots
; are maximized, and which axis they are attached on.
;
res1 = True
res2 = True
res1@gsnMaximize = True
res2@gsnAttachPlotsXAxis = True
; xy1 will be the base plot.
amid = gsn_attach_plots(xy1,(/xy2,xy3,xy4,xy5,xy6,xy7/),res1,res2)
draw(xy1) ; All four plots will be drawn.
frame(wks)
;**Sharon comment out-do not need for testing
; Resize base plot and watch how other plots follow.
; setvalues xy1
; "vpWidthF" : 0.4
; "vpHeightF" : 0.15
; end setvalues
;
; draw(xy1) ; All four plots will be smaller.
; frame(wks)
end