Re: Overlay is not working

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Fri Jan 04 2013 - 22:46:36 MST

Hi Abhik,
I think it might be best to simplify your script a bit. But to answer your question about why you had to use a ps file instead of a eps file: eps files cannot have more that one frame in them.
The maximize_output documentation states that the plots will be drawn and the frame will be advanced, which is why you are getting 6 frames. (http://www.ncl.ucar.edu/Document/Graphics/Interfaces/maximize_output.shtml)

If you wish to use maximize_output I would only call it once after the two calls to gsn_panel.

Try this, setting vpWidthF and vpHeightF =0.6 in both the res and xyres resource lists:
(... = leave the coding the same as you have it)
do j =0,5
.....
res = True
.......
plotz(j) = gsn_csm_contour(wks,z,res)
xyres =True
........
plotx(j) = gsn_csm_xy(wks,lon,x,xyres)
delete(ntim)
delete(x)
delete(z)
j = j+1
end do
resP = True
.... ; do not set gsnMaximize = True in the panel resource list
gsn_panel(wks,plotz,(/6,1/),resP) ; create panel
gsn_panel(wks,plotx,(/6,1/),resP) ; create panel
txres = True
txres@txAngleF = 90. ; Rotate string clockwise
txres@txFontHeightF = 0.01
gsn_text_ndc(wks," Pressure (hPa) ",0.34,0.68,txres)
maximize_output(wks,False)
end

Let ncl-talk know if that doesn't fix things...
Adam

On Jan 4, 2013, at 4:46, Abhik Santra <abhiksantra@tropmet.res.in> wrote:

>
> Hi Adam,
>
> My plot doesn't involve any map. It contains the latitude averaged vertical distribution over the longitude belt.
> So the mpFreeShapeMode = "FreeAspect" is not a valid resource for gsn_csm_contour.
> I have made some progress by introducing "maximize_output(wks,res)" inside the do loop.
> It is plotting the output from gsn_csm_xy over the output from gsn_csm_contour.
> But the panels are now not working and the output file type has been changed from eps to ps.
> Presently, 6 plots appear on 6 different pages without having the common labelbar.
> But I want to make a panel plot for all of them.
> How can I solve this issue?
>
> I am attaching the output ps file and my present scrips is as follows:
>
>>> begin
>>>
>>> plotx = new(6,graphic)
>>> plotz = new(6,graphic)
>>> wks = gsn_open_wks("ps","test")
>>> gsn_define_colormap(wks,"BlWhRe")
>>>
>>>
>>> do j=0, 5
>>>
>>> f1 = addfile ("XZ"+j+".nc" , "r") : res: 1.25Dx1.25D
>>> f2 = addfile ("X"+j+".nc" , "r") ; res: 1Dx1D
>>>
>>> z = f1->zz(0,:,:)
>>> x = f2->xx(0,:)
>>>
>>> lon = xx&lon
>>>
>>>
>>> res = True
>>> res@cnFillOn = True ; turn on color fill
>>> res@gsnDraw = False ; do not draw picture
>>> res@gsnFrame = False ; do not advance frame
>>> res@lbLabelBarOn = False ; no individual label bars
>>> res@gsnSpreadColors = True ; use full colormap
>>> res@cnLinesOn = True ; no contour lines
>>> res@cnLineThicknessF = 0.6
>>> res@cnLineColor = "gray"
>>> res@cnInfoLabelOn = False ; turn off cn info label
>>> res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
>>> res@cnMinLevelValF = -0.3 ; set min contour level
>>> res@cnMaxLevelValF = 0.3 ; set max contour level
>>> res@cnLevelSpacingF = 0.05 ; set contour spacing
>>> res@cnLineLabelsOn = False
>>> res@tmXBLabelFontHeightF = 0.0
>>> res@tmYLLabelFontHeightF = 0.018
>>> res@tmYROn = False
>>> res@tmYRMinorOn = False
>>> res@trYReverse = True
>>> res@vpHeightF = 0.2 ; default 0.6
>>> res@vpWidthF = 0.8 ; default 0.6
>>>
>>> plotz(j) = gsn_csm_contour(wks,z,res) ; !! This is only coming in the panel !!
>>>
>>> xyres = True
>>> xyres@gsnDraw = False ; don't draw
>>> xyres@gsnFrame = False
>>> xyres@tmXTOn = False
>>> xyres@tmYLOn = False
>>> xyres@tmYROn = True
>>> xyres@tmYRLabelsOn = True
>>> xyres@trYMinF = -5. ; set Y-axis max and mins
>>> xyres@trYMaxF = 5.
>>> xyres@gsnYRefLine = 0. ; Y-value for ref. line
>>> xyres@xyLineThicknesses = (/3./) ; Define line thicknesses
>>> xyres@xyLineColors = (/"black"/) ; Define line color
>>> xyres@trXMaxF = 360.
>>>
>>> plotx(j) = gsn_csm_xy(wks,lon,x,xyres)
>>>
>>> delete(res)
>>> delete(xyres)
>>> delete(ntim)
>>> delete(x)
>>> delete(z)
>>> psres = True
>>> maximize_output(wks,psres)
>>>
>>> j=j+1
>>>
>>> end do
>>> ;*******************************************
>>> ; create panel resources
>>> ;*******************************************
>>> resP = True ; mods desired
>>> resP@gsnFrame = False ; save panel until all ready
>>> ;resP@gsnMaximize = True ; Maximize in frame
>>> resP@gsnPanelBottom = 0.35
>>> resP@gsnPanelLabelBar = True ; commom label bar
>>> resP@lbLabelStride = 2 ; every 2nd label
>>> resP@lbLabelFontHeightF = 0.01
>>> resP@pmLabelBarHeightF = 0.06
>>> resP@gsnPanelFigureStringsFontHeightF = 0.007
>>> resP@pmLabelBarOrthogonalPosF = 0.01
>>> resP@gsnAttachPlotsXAxis = True
>>> resP@gsnScale = True
>>>
>>> gsn_panel(wks,plotz,(/6,1/),resP) ; create panels
>>> txres = True
> txres@txAngleF = 90. ; Rotate string clockwise
> txres@txFontHeightF = 0.01
> gsn_text_ndc(wks," Pressure (hPa) ",0.34,0.68,txres)
>>> frame(wks)
>>> end
>
> Regards,
> Abhik
>
>
>
> ----- Original Message -----
> From: "Adam Phillips" <asphilli@ucar.edu>
> To: ncl-talk@ucar.edu
> Sent: Thursday, January 3, 2013 10:56:45 PM
> Subject: Re: Overlay is not working
>
> Hi Abhik,
> Without having your script and data it is hard to see what could
> possibly be wrong. One guess would be that as your first panel plots
> involve maps, that NCL will not resize the maps so as to not alter the
> aspect ratio of the maps without you explicitly telling it to do so,
> regardless of whether you have vpWidthF and vpHeightF set. See example
> #3 here:
> http://www.ncl.ucar.edu/Applications/resize.shtml#ex3
> (setting mpFreeShapeMode = "FreeAspect" will tell NCL to alter the
> aspect ratio)
>
> Note though, that setting the above can seriously distort your map. If
> you don't mind doing that then setting mpFreeShapeMode is the way to go.
>
> Finally, hopefully you saw Mary Haley's correction to my reply yesterday
> afternoon. You can use overlay to place a XY plot on a map plot,
> provided that the X and Y axis ranges match between the two plots. If
> the ranges do no match though, going with my method #2 is the way to go..
> Adam
>
> On 01/02/2013 11:09 PM, Abhik Santra wrote:
>> Hi Adam,
>>
>> Thank you for your suggestions.
>> I followed your 2nd method and able to overlap the 2 set of plots.
>> But I am unable to control the viewport and as a result the plots are not exactly overlapped.
>> I used vpWidthF and vpHeightF as 0.8 and 0.2 respectively for both the panels.
>> But the plots at 2nd panel are appeared larger than that of the 1st panel.
>> The gsnPanelDebug for 1st panel are as follows:
>> plot #0
>> (0) new x,y = 0.381421,0.993689
>> (0) orig wdt,hgt = 0.8,0.2
>> (0) new wdt,hgt = 0.265712,0.0664279
>> (0) -------Panel viewport values for each plot-------
>> (0) plot #1
>> (0) new x,y = 0.381421,0.914572
>> (0) orig wdt,hgt = 0.8,0.2
>> (0) new wdt,hgt = 0.265712,0.0664279
>> (0) -------Panel viewport values for each plot-------
>> (0) plot #2
>> (0) new x,y = 0.381421,0.835455
>> (0) orig wdt,hgt = 0.8,0.2
>> (0) new wdt,hgt = 0.265712,0.0664279
>> (0) -------Panel viewport values for each plot-------
>> (0) plot #3
>> (0) new x,y = 0.381421,0.756338
>> (0) orig wdt,hgt = 0.8,0.2
>> (0) new wdt,hgt = 0.265712,0.0664279
>> (0) -------Panel viewport values for each plot-------
>> (0) plot #4
>> (0) new x,y = 0.381421,0.677221
>> (0) orig wdt,hgt = 0.8,0.2
>> (0) new wdt,hgt = 0.265712,0.0664279
>> (0) -------Panel viewport values for each plot-------
>> (0) plot #5
>> (0) new x,y = 0.381421,0.598104
>> (0) orig wdt,hgt = 0.8,0.2
>> (0) new wdt,hgt = 0.265712,0.0664279
>>
>> Should I use vpXF and vpYF for the 2nd panel?
>> Or should I use same vpXF and vpYF for both the panels?
>> What will be their values for the plots at the 2nd panels?
>> Please let me know the same.
>>
>> Regards,
>> Abhik
>>
>>
>>
>>
>> ----- Original Message -----
>> From: "Adam Phillips" <asphilli@ucar.edu>
>> To: ncl-talk@ucar.edu
>> Sent: Wednesday, January 2, 2013 11:05:59 PM
>> Subject: Re: Overlay is not working
>>
>> Hi Abhik,
>> It looks like you are trying to overlay a XY plot onto a spatial map
>> plot. I would venture to guess that NCL isn't sure how to overlay the 2,
>> as the plot types are completely different.
>>
>> Someone might have a better alternative, but I see two possibilities:
>> 1) Create all 6 map plots, call gsn_panel (but don't advance the frame
>> by setting gsnFrame = False in the Panel resource list), create all 6 XY
>> plots, call gsn_panel, manually advance the frame. You may have to
>> adjust the vpWidthF/vpHeightF resources for the XY plots, and you will
>> likely have to set gsnPanelXWhiteSpacePercent,
>> gsnPanelYWhiteSpacePercent, gsnPanelBottom,gsnPanelTop,gsnPanelRight and
>> gsnPanelLeft in the Panel resource lists to try to get things lined up
>> correctly.
>>
>> 2) First create all 6 map plots, call gsn_panel (but don't advance the
>> frame by setting gsnFrame = False in the Panel resource list). Draw each
>> XY plot individually, exactly specifying the placement over each of your
>> 6 map plots via the vpXY/vpYF resources. In this scenario you will want
>> to set gsnFrame = False in the xy resource list, and at the end of the
>> script call frame(wks)..
>>
>> I'd recommend trying method 2 first, as even though that method is more
>> tedious than the 1st method, you have a higher chance of lining things
>> up exactly as you want them..
>>
>> If you have further questions about this issue please respond to ncl-talk.
>> Good luck,
>> Adam
>>
>> On 01/02/2013 01:08 AM, Abhik Santra wrote:
>>> Hello ncl-talk,
>>>
>>> I am trying to make 6 overlay plots in a single panel from two different datasets having different resolutions (1.25x1.25 and 1x1 degrees).
>>> But my overlay plots didn't work appropriately as only one set of figures are appeared in the panel.
>>>
>>> I have the script as follow:
>>>
>>>
>>> begin
>>>
>>> plot = new(6,graphic)
>>> wks = gsn_open_wks("eps","test")
>>> gsn_define_colormap(wks,"BlWhRe")
>>>
>>>
>>> do j=0, 5
>>>
>>> f1 = addfile ("XZ"+j+".nc" , "r") : res: 1.25Dx1.25D
>>> f2 = addfile ("X"+j+".nc" , "r") ; res: 1Dx1D
>>>
>>> z = f1->zz(0,:,:)
>>> x = f2->xx(0,:)
>>>
>>> lon = xx&lon
>>>
>>>
>>> res = True
>>> res@cnFillOn = True ; turn on color fill
>>> res@gsnDraw = False ; do not draw picture
>>> res@gsnFrame = False ; do not advance frame
>>> res@lbLabelBarOn = False ; no individual label bars
>>> res@gsnSpreadColors = True ; use full colormap
>>> res@cnLinesOn = True ; no contour lines
>>> res@cnLineThicknessF = 0.6
>>> res@cnLineColor = "gray"
>>> res@cnInfoLabelOn = False ; turn off cn info label
>>> res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels
>>> res@cnMinLevelValF = -0.3 ; set min contour level
>>> res@cnMaxLevelValF = 0.3 ; set max contour level
>>> res@cnLevelSpacingF = 0.05 ; set contour spacing
>>> res@cnLineLabelsOn = False
>>> res@tmXBLabelFontHeightF = 0.0
>>> res@tmYLLabelFontHeightF = 0.018
>>> res@tmYROn = False
>>> res@tmYRMinorOn = False
>>> res@trYReverse = True
>>> res@vpHeightF = 0.2 ; default 0.6
>>> res@vpWidthF = 0.8 ; default 0.6
>>>
>>> plotz = gsn_csm_contour(wks,z,res) ; !! This is only coming in the panel !!
>>>
>>> xyres = True
>>> xyres@gsnDraw = False ; don't draw
>>> xyres@gsnFrame = False
>>> xyres@tmXTOn = False
>>> xyres@tmYLOn = False
>>> xyres@tmYROn = True
>>> xyres@tmYRLabelsOn = True
>>> xyres@trYMinF = -5. ; set Y-axis max and mins
>>> xyres@trYMaxF = 5.
>>> xyres@gsnYRefLine = 0. ; Y-value for ref. line
>>> xyres@xyLineThicknesses = (/3./) ; Define line thicknesses
>>> xyres@xyLineColors = (/"black"/) ; Define line color
>>> xyres@trXMaxF = 360.
>>>
>>> plotx = gsn_csm_xy(wks,lon,x,xyres)
>>> overlay(plotz,plotx)
>>> plot(j) = plotz
>>>
>>> delete(plotz)
>>> delete(plotx)
>>> delete(res)
>>> delete(xyres)
>>> delete(ntim)
>>> delete(x)
>>> delete(z)
>>>
>>> j=j+1
>>>
>>> end do
>>> ;*******************************************
>>> ; create panel resources
>>> ;*******************************************
>>> resP = True ; mods desired
>>> resP@gsnFrame = False ; save panel until all ready
>>> ;resP@gsnMaximize = True ; Maximize in frame
>>> resP@gsnPanelBottom = 0.35
>>> resP@gsnPanelLabelBar = True ; commom label bar
>>> resP@lbLabelStride = 2 ; every 2nd label
>>> resP@lbLabelFontHeightF = 0.01
>>> resP@pmLabelBarHeightF = 0.06
>>> resP@gsnPanelFigureStringsFontHeightF = 0.007
>>> resP@pmLabelBarOrthogonalPosF = 0.01
>>> resP@gsnAttachPlotsXAxis = True
>>> resP@gsnScale = True
>>>
>>> gsn_panel(wks,plot,(/6,1/),resP) ; create panels
>>>
>>> frame(wks)
>>> end
>>>
>>> Can anyone suggest me the way to solve this problem?
>>> Thanks in advance and wish you a happy new year.
>>>
>>> Regards,
>>> Abhik
>>> ______________________________
>>> Abhik Santra
>>> CSIR Research Fellow,
>>> Indian Institute of Tropical Meteorology,
>>> Pune - 411008.
>>> India
>>> _______________________________________________
>>> ncl-talk mailing list
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> ______________________________________________________________
> Adam Phillips asphilli@ucar.edu
> NCAR/Climate and Global Dynamics Division (303) 497-1726
> P.O. Box 3000
> Boulder, CO 80307-3000 http://www.cgd.ucar.edu/cas/asphilli
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> --
> ___________________________________________
>
> Abhik Santra
> CSIR Research Fellow,
> Indian Institute of Tropical Meteorology,
> Pune - 411008.
> India
> ___________________________________________
> <test.ps>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jan 4 22:45:42 2013

This archive was generated by hypermail 2.1.8 : Mon Jan 07 2013 - 08:57:08 MST