[ncl-talk] XY plot with multiple vertical axes

Giorgio Graffino g.graffino at tim.it
Wed Jul 7 05:33:15 MDT 2021


Dear NCL folks,

I'm trying to draw a XY plot by attaching four subplots together and 
giving each of them its own vertical axis. This last point is 
particularly tricky. Taking inspiration from this example 
(https://www.ncl.ucar.edu/Applications/Scripts/xy_22.ncl), I'm trying 
now to draw individual vertical axis using gsn_blank_plot, but I can't 
make all the plots to arrange nicely (see 
HadCM3_plot_temp_ohue.000003.png) even when I explicitly set the NDC 
coordinates of the main plot (see code snippet below).

What I'd like to have is something like 
HadCM3_plot_temp_ohue.000004.png, but with individual axes for each 
subplot. Can it be done? Is there an easier way to get a nice result?

Cheers,
Giorgio

deltapl = fspan(0.2,0.8,5)
; resa at gsnMaximize       = True
  resa at gsnDraw           = False   ; Don't draw plot
  resa at gsnFrame          = False   ; Don't advance frame
  resa at gsnYRefLine       = 0.
  resa at tiMainString      = ""
  resa at tiMainFontHeightF = 0.015
  resa at tiXAxisString     = ""
  resa at tiYAxisString     = ""
  resa at tiYAxisFontHeightF = 0.0125
  resa at tmXBMode          = "Explicit"
  resa at tmXBLabelAngleF   = 45.
  resa at tmXBLabelFontHeightF = 0.0125
  resa at tmXBLabelJust     = "TopRight"
  resa at tmXBLabels        := (/"Pos","Neg"/)
  resa at tmXBValues        := (/0.8,1.2/)
  resa at tmXUseBottom      = False
  resa at tmXTLabelsOn      = True
  resa at tmXTMode          = "Explicit"
  resa at tmXTLabelAngleF   = 45.
  resa at tmXTLabelFontHeightF = 0.0125
  resa at tmXTLabelJust     = "BottomLeft"
  resa at tmXTLabels        = labels1(0)
  resa at tmXTValues        = 1.
  resa at tmYLLabelFontHeightF = 0.0125
  resa at trXMinF           = 0.5
  resa at trXMaxF           = 1.5
  resa at trYMinF           = 0.
  resa at trYMaxF           = 0.5
  resa at vpHeightF         = 0.8
  resa at vpWidthF          = 0.15
  resa at vpXF              = 0.2
  resa at vpYF              = 0.8
  resa at xyMarkLineMode    = "Markers"                ; choose to use 
markers
  resa at xyMarkers         := markrs
  resa at xyMarkerColors    := (/"Black","Red","Pink","Grey"/)
  resa at xyMarkerSizeF     = 0.015                    ; Marker size 
(default 0.01)
  resa at xyMarkerThicknessF = 3.
; resb at gsnMaximize       = True
  resb at gsnDraw           = False   ; Don't draw plot
  resb at gsnFrame          = False   ; Don't advance frame
  resb at tiMainFontHeightF = 0.015
  resb at trXMinF           = 0.5
  resb at trXMaxF           = 1.5
  resb at trYMinF           = 0.
  resb at trYMaxF           = 0.5
  resb at xyMarkLineMode    = "Markers"                ; choose to use 
markers
  resb at xyMarkers         := markrs
  resb at xyMarkerColors    := (/"Purple","Blue","Cyan","Green"/)
  resb at xyMarkerSizeF     = 0.015                    ; Marker size 
(default 0.01)
  resb at xyMarkerThicknessF = 3.
  resb at vpHeightF         = 0.8
  resb at vpWidthF          = 0.15
  resb at vpXF              = 0.2
  resb at vpYF              = 0.8
  resz at gsnDraw      = False
  resz at gsnFrame     = False
  resz at tmXBOn       = False      ; Turn off X axis since it has already
  resz at tmXBBorderOn = False      ; been drawn.
  resz at tmXBLabelsOn = False
  resz at tmXTOn       = False
  resz at tmXTBorderOn = False
  resz at tmXTLabelsOn = False
  resz at tmYLOn       = True       ; Turn on left Y axis.
  resz at tmYLBorderOn = True
  resz at tmYLLabelsOn = True
  resz at tmYLLabelFontHeightF = 0.0125
  resz at tmYROn       = False
  resz at tmYRBorderOn = False
  resz at tmYRLabelsOn = False
  resz at vpHeightF    = 0.75
  resz at vpYF         = 0.85


  plot1a = 
gsn_csm_xy(wks,transpose((/(/0.8,0.8,0.8,0.8/),(/0.8,0.8,0.8,0.8/)/)),transpose((/abs(tas_globalave_positiveforcing(0:6:2)),abs(tas_globalave_positiveforcing(0:6:2))/)),resa)
  plot1b = 
gsn_csm_xy(wks,transpose((/(/1.2,1.2,1.2,1.2/),(/1.2,1.2,1.2,1.2/)/)),transpose((/abs(tas_globalave_negativeforcing(0:6:2)),abs(tas_globalave_negativeforcing(0:6:2))/)),resb)
; resa at tiMainString      = "HadCM3 -"
  resa at tmXTLabels        = labels1(1)
  resa at trYMinF           = 0.
  resa at trYMaxF           = 1.5
  resb at trYMinF           = 0.
  resb at trYMaxF           = 1.5
  resz at trYMinF           = 0.
  resz at trYMaxF           = 1.5
  resz at vpXF              = deltapl(1)
  plot2a = 
gsn_csm_xy(wks,transpose((/(/0.8,0.8,0.8,0.8/),(/0.8,0.8,0.8,0.8/)/)),transpose((/abs(sst_globalave_positiveforcing(0:6:2)),abs(sst_globalave_positiveforcing(0:6:2))/)),resa)
  plot2b = 
gsn_csm_xy(wks,transpose((/(/1.2,1.2,1.2,1.2/),(/1.2,1.2,1.2,1.2/)/)),transpose((/abs(sst_globalave_negativeforcing(0:6:2)),abs(sst_globalave_negativeforcing(0:6:2))/)),resb)
  plot2z = gsn_blank_plot(wks,resz)
; resa at tiMainString      = "Seasonal Cycle"
  resa at tmXTLabels        = labels1(2)
  resa at trYMinF           = 0.
  resa at trYMaxF           = 1.5
  resb at trYMinF           = 0.
  resb at trYMaxF           = 1.5
  resz at trYMinF           = 0.
  resz at trYMaxF           = 1.5
  resz at vpXF              = deltapl(2)
  plot3a = 
gsn_csm_xy(wks,transpose((/(/0.8,0.8,0.8,0.8/),(/0.8,0.8,0.8,0.8/)/)),transpose((/abs(trac_globalave_positiveforcing(0:6:2)),abs(trac_globalave_positiveforcing(0:6:2))/)),resa)
  plot3b = 
gsn_csm_xy(wks,transpose((/(/1.2,1.2,1.2,1.2/),(/1.2,1.2,1.2,1.2/)/)),transpose((/abs(trac_globalave_negativeforcing(0:6:2)),abs(trac_globalave_negativeforcing(0:6:2))/)),resb)
  plot3z = gsn_blank_plot(wks,resz)
; resa at tiMainString      = ""
  resa at tmXTLabels        = labels1(3)
  resa at trYMinF           = 0.
  resa at trYMaxF           = 35.
  resb at trYMinF           = 0.
  resb at trYMaxF           = 35.
  resz at trYMinF           = 0.
  resz at trYMaxF           = 35.
  resz at vpXF              = deltapl(3)
  plot4a = 
gsn_csm_xy(wks,transpose((/(/0.8,0.8,0.8,0.8/),(/0.8,0.8,0.8,0.8/)/)),transpose((/abs(tas_ohue_positiveforcing(0:6:2)),abs(tas_ohue_positiveforcing(0:6:2))/)),resa)
  plot4b = 
gsn_csm_xy(wks,transpose((/(/1.2,1.2,1.2,1.2/),(/1.2,1.2,1.2,1.2/)/)),transpose((/abs(tas_ohue_negativeforcing(0:6:2)),abs(tas_ohue_negativeforcing(0:6:2))/)),resb)
  plot4z = gsn_blank_plot(wks,resz)
  overlay(plot1a,plot1b)
  overlay(plot2a,plot2b)
  overlay(plot3a,plot3b)
  overlay(plot4a,plot4b)
  drawNDCGrid(wks)
  attplot = 
gsn_attach_plots(plot1a,(/plot2a,plot3a,plot4a/),at_res,False)
  draw(plot1a)
  draw(plot2z)
  draw(plot3z)
  draw(plot4z)
do i = 0, dimsizes(ypos1)-1
  lb_res at lbFillColors     = colors(i)
  lb_res at lbLabelFontColor = colors(i)
  gsn_labelbar_ndc(wks,1,labels2(i),0.85,ypos1(i),lb_res)
end do
do i = 0, dimsizes(ypos2)-1
  mk_res at gsMarkerIndex    = markrs(i)
  gsn_polymarker_ndc(wks,0.875,ypos2(i),mk_res)
  gsn_text_ndc(wks,labels3(i),0.9,ypos2(i),tx_res)
end do
  frame(wks)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210707/e53035c5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HadCM3_plot_temp_ohue.000003.png
Type: image/png
Size: 136218 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210707/e53035c5/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HadCM3_plot_temp_ohue.000004.png
Type: image/png
Size: 123317 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210707/e53035c5/attachment-0001.png>


More information about the ncl-talk mailing list