[ncl-talk] XY plot with multiple vertical axes

Adam Phillips asphilli at ucar.edu
Fri Jul 9 12:08:19 MDT 2021


Hi Giorgio,
You have a lot going on in the code snippet you sent, with numerous calls
to gsn_attach_plots and overlay. Yes, it is possible to do what you want,
but as you can tell already there is a bit of art to this. I would
recommend not setting gsnMaximize for anything (which you are not), and pay
particular attention to the vpYF/vpHeightF settings for your various
resource lists. The values should be identical across your resa, resb and
rez resource lists, otherwise the sizes and locations of the plots will be
different.  I'd try setting vpYF = 0.8 and vpHeightF = 0.6 to start.
Finally, I would not call drawNDCGrids until right before the frame(wks)
call as it freezes the size of the frame. That shouldn't affect anything
with your script as you are not maximizing, but just to be sure I would
move the call.

Hope the above helps!
Adam



On Wed, Jul 7, 2021 at 5:33 AM Giorgio Graffino via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> 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)
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk



-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20210709/8ce6ce38/attachment.html>


More information about the ncl-talk mailing list