[ncl-talk] Panel different sizes plots to equal height
Adam Phillips
asphilli at ucar.edu
Tue May 15 13:59:00 MDT 2018
Hi Tabish,
Looking again at the script you originally sent, you do not use any of the
wrf plotting functions (like wrf_contour), instead
using gsn_csm_contour_map. You also have numerous lines commented out, and
included resource lists that are not used (example: res). If you are using
a different script than what you sent, it is impossible for ncl-talk to
assist. Please send to ncl-talk the latest clean code that you have.
Adam
On Mon, May 14, 2018 at 6:48 PM, Tabish Ansari <tabishumaransari at gmail.com>
wrote:
> Hi
>
> I tried to forego the gsn_panel and specify the vp resources instead but
> both the plots get drawn on top of each other in full size.
> Also, when I try to comment out the line:
> pltres at PanelPlot = True
>
> I do not get the station points correctly mapped onto the contour maps.
>
> Should I use "pltres at PanelPlot = True" even when not using gsn_panel?
>
> Should I use the vp resources with res (which go into wrf_contour
> function) or with pltres (which go into wrf_map_overlays function)?
> I have tried using both but nothing happens.
>
>
> Please let me know how can I place the plots side by side.
>
>
>
> Tabish U Ansari
> PhD student, Lancaster Environment Center
> Lancaster Univeristy
> Bailrigg, Lancaster,
> LA1 4YW, United Kingdom
>
> On 14 May 2018 at 20:09, Adam Phillips <asphilli at ucar.edu> wrote:
>
>> Hi Tabish,
>> It might be easiest to forego using gsn_panel, and panel the two plots
>> manually as is shown in panel example #20 here:
>> http://www.ncl.ucar.edu/Applications/panel.shtml#ex20
>>
>> As you are currently drawing a labelbar using gsn_panel, you will want to
>> do this by setting the appropriate resources in the individual resource
>> list cnres:
>> cnres at lbLabelBarOn = True
>> cnres at pmLabelBarHeightF = 0.1
>> cnres at pmLabelBarWidhtF = 0.8
>> cnres at lbLabelFontHeightF = 0.020
>> cnres at pmLabelBarParallelPosF = -0.25 ; This resource shifts the
>> labelbar left or right, so you can center the labelbar on the page. You
>> will likely have to go through some trial and error on this setting.
>>
>> Alternatively, you can draw your own labelbar by calling
>> gsn_labelbar_ndc. See maps only example #6 here:
>> http://www.ncl.ucar.edu/Applications/maponly.shtml#ex6
>>
>> Hope that helps. If you have further questions please respond to the
>> ncl-talk email list.
>> Adam
>>
>>
>>
>> On Mon, May 14, 2018 at 11:46 AM, Tabish Ansari <
>> tabishumaransari at gmail.com> wrote:
>>
>>> Hi Adam,
>>>
>>> Thanks for your reply.
>>> The eps figure from the current script is attached.
>>> I just want to shrink the second figure or expand the first figure to
>>> make them both same in height without changing the aspect ratio.
>>>
>>> Thanks
>>>
>>> Tabish
>>>
>>> Tabish U Ansari
>>> PhD student, Lancaster Environment Center
>>> Lancaster Univeristy
>>> Bailrigg, Lancaster,
>>> LA1 4YW, United Kingdom
>>>
>>> On 14 May 2018 at 16:25, Adam Phillips <asphilli at ucar.edu> wrote:
>>>
>>>> Hi Tabish,
>>>> It would help the community answer your question if you could attach an
>>>> image showing your plot.
>>>> Thanks,
>>>> Adam
>>>>
>>>> On Sun, May 13, 2018 at 4:03 PM, Tabish Ansari <
>>>> tabishumaransari at gmail.com> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> I am trying to panel my WRF domains: domain1 and domain3 which have
>>>>> very different aspect ratios and sizes. Currently using the following
>>>>> script I'm able to panel them together but not change their size. I tried
>>>>> using vp resources but without success. Can you please let me know what
>>>>> changes I make to this script to make the D03 same in height as D01 without
>>>>> changing aspect ratios?
>>>>>
>>>>> Here's the script:
>>>>> ; PANELPLOT OF WRF-CHEM D01 AND D03 PM2.5 CONCENTRATIONS CONTOUR MAPS
>>>>> ALONG WITH OBSERVATIONS
>>>>> 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/wrf/WRFUserARW.ncl"
>>>>>
>>>>> ;-----------------------------------------------------------
>>>>> -----------
>>>>> ; Procedure to attach colored markers to an NCL map, given 1D
>>>>> ; data, and lat/lon arrays, a set of levels, and a color map.
>>>>> ;-----------------------------------------------------------
>>>>> -----------
>>>>> procedure add_obs_markers_to_map(wks,plot,levels,colormap,data_1d,lat_
>>>>> 1d,lon_1d)
>>>>> local mkres, nlevels, colors, nlevels, n, ii
>>>>> begin
>>>>>
>>>>> ;---Set resources for the markers
>>>>> mkres = True
>>>>> mkres at gsMarkerIndex = 16
>>>>> mkres at gsMarkerSizeF = 0.0035
>>>>> ; Based on the levels we had for the contour plot and the colormap
>>>>> used,
>>>>> ; get an array of colors that span the colormap. This uses the same
>>>>> ; algorithm that the contour used, so the colors will be identical.
>>>>> ;
>>>>> nlevels = dimsizes(levels)
>>>>> colors = span_color_rgba(colormap,nlevels+1) ; Need one more
>>>>> color than number of levels
>>>>>
>>>>> ;
>>>>> ; Loop through each level, gather all the data values in the given
>>>>> level
>>>>> ; range, and add colored markers to the existing map.
>>>>> ;
>>>>> do n=0,nlevels
>>>>>
>>>>> ;---These "if" statements are how color contours are handled in NCL.
>>>>> if(n.eq.0) then
>>>>> ii := ind(data_1d.lt.levels(n))
>>>>> else if(n.eq.nlevels) then
>>>>> ii := ind(data_1d.ge.levels(n-1))
>>>>> else
>>>>> ii := ind(data_1d.ge.levels(n-1).and.data_1d.lt.levels(n))
>>>>> end if
>>>>> end if
>>>>> if(any(ismissing(ii))) then
>>>>> continue
>>>>> end if
>>>>>
>>>>> ;---Add the markers
>>>>> mkres at gsMarkerColor = colors(n,:) ; colors is an N x 4 array
>>>>> plot@$unique_string("markers")$ = gsn_add_polymarker(wks,plot,lo
>>>>> n_1d(ii),lat_1d(ii),mkres)
>>>>> end do
>>>>> end
>>>>>
>>>>> ;-----------------------------------------------------------
>>>>> -----------
>>>>> ; Main code
>>>>> ;-----------------------------------------------------------
>>>>> -----------
>>>>> begin
>>>>>
>>>>> ;---Open WRF output file and read data
>>>>>
>>>>> DATADir = "/data2/tabish/control-run-so4-ECMWF/"
>>>>> FILES = systemfunc (" ls -1 " + DATADir + "wrfout_d01_2014-10* ")
>>>>> numFILES = dimsizes(FILES)
>>>>>
>>>>> s=1
>>>>> a = addfile(FILES(0)+".nc","r"); THIS IS JUST FOR INITIALIZATION OF
>>>>> PM25 ARRAY, IT WILL BE SUBSTRACTED FROM THE SUM IN THE END
>>>>> pm25init = a->PM2_5_DRY(15,0,:,:)
>>>>> pm25sum = pm25init
>>>>> times = wrf_user_getvar(a,"times",-1) ; get all times in the file
>>>>> ntimes = dimsizes(times)
>>>>> do it = 16,ntimes-1,1 ; TIME LOOP
>>>>> s=s+1
>>>>> print("Working on time: " + times(it) )
>>>>> pm25sum = pm25sum + a->PM2_5_DRY(it,0,:,:)
>>>>> end do ; END OF TIME LOOP
>>>>>
>>>>> do ifil = 1,numFILES-2 ; FILE LOOP
>>>>> a = addfile(FILES(ifil)+".nc","r") ; Open the next file
>>>>> times = wrf_user_getvar(a,"times",-1) ; get all times in the file
>>>>> ntimes = dimsizes(times)
>>>>> do it = 0,ntimes-1,1 ; TIME LOOP
>>>>> s=s+1
>>>>> print("Working on time: " + times(it) )
>>>>> pm25sum = pm25sum + a->PM2_5_DRY(it,0,:,:)
>>>>> end do ; END OF TIME LOOP
>>>>> end do
>>>>>
>>>>> a = addfile(FILES(numFILES-1)+".nc","r") ; Open the next file
>>>>> times = wrf_user_getvar(a,"times",-1) ; get all times in the file
>>>>> ntimes = dimsizes(times)
>>>>> do it = 0,16,1 ; TIME LOOP
>>>>> s=s+1
>>>>> print("Working on time: " + times(it) )
>>>>> pm25sum = pm25sum + a->PM2_5_DRY(it,0,:,:)
>>>>> end do ; END OF TIME LOOP
>>>>>
>>>>> pm25_avg= pm25sum/s
>>>>> pm25_avg at description = "PM2.5 conc in ug/m3"
>>>>>
>>>>> lat2d = wrf_user_getvar(a,"XLAT",it) ; latitude/longitude
>>>>> lon2d = wrf_user_getvar(a,"XLONG",it)
>>>>>
>>>>> pm25_avg at lat2d = lat2d ; for plotting
>>>>> pm25_avg at lon2d = lon2d
>>>>> ;---Will use this for contours and filled markers
>>>>> colormap = "BlAqGrYeOrReVi200"
>>>>> ;levels = ispan(0,180,9)
>>>>> levels = (/0,2,5,10,15,20,25,30,35,40,4
>>>>> 5,50,55,60,65,70,80,90,100,110,160,200/)
>>>>>
>>>>> wks = gsn_open_wks("x11","wrf_obs_d01-d03_pm25")
>>>>>
>>>>> ;---Common resources shared by both contour plot and marker plot
>>>>> res = True
>>>>> res at gsnMaximize = True
>>>>> res at gsnLeftString = ""
>>>>> res at gsnRightString = ""
>>>>>
>>>>> res at mpDataBaseVersion = "MediumRes"
>>>>> ; res at mpFillOn = False
>>>>> ; res at mpMinLatF = min(pm25_avg at lat2d)
>>>>> ; res at mpMaxLatF = max(pm25_avg at lat2d)
>>>>> ; res at mpMinLonF = min(pm25_avg at lon2d)
>>>>> ; res at mpMaxLonF = max(pm25_avg at lon2d)
>>>>> ; res at pmTickMarkDisplayMode = "Always" ; better map tickmarks
>>>>>
>>>>> res at mpLimitMode = "Corners" ; choose range of map
>>>>> res at mpLeftCornerLatF = 51.8
>>>>> res at mpLeftCornerLonF = 82.6
>>>>> res at mpRightCornerLatF = 22.66
>>>>> res at mpRightCornerLonF = 130.499
>>>>> res at mpProjection = "LambertConformal"
>>>>> res at mpLambertParallel1F = 20
>>>>> res at mpLambertParallel2F = 50
>>>>> res at mpLambertMeridianF = 110
>>>>>
>>>>>
>>>>>
>>>>> ;---Resources for filled contour plot
>>>>> cnres = res
>>>>> cnres at cnFillOn = True
>>>>> cnres at cnLevelSelectionMode = "ExplicitLevels"
>>>>> cnres at cnLevels = levels
>>>>> cnres at cnFillPalette = colormap
>>>>> cnres at cnLinesOn = False
>>>>> cnres at cnLineLabelsOn = False
>>>>> cnres at lbLabelBarOn = False ; will add in panel later
>>>>> cnres at pmTitleZone = 2 ; move title down
>>>>> cnres at gsnAddCyclic = False
>>>>> cnres at mpLimitMode = "Corners" ; choose range of map
>>>>> cnres at mpLeftCornerLatF = 51.8
>>>>> cnres at mpLeftCornerLonF = 82.6
>>>>> cnres at mpRightCornerLatF = 22.66
>>>>> cnres at mpRightCornerLonF = 130.499
>>>>> cnres at mpProjection = "LambertConformal"
>>>>> cnres at mpLambertParallel1F = 20
>>>>> cnres at mpLambertParallel2F = 50
>>>>> cnres at mpLambertMeridianF = 110
>>>>>
>>>>> cnres at mpFillOn = True
>>>>> cnres at mpOutlineDrawOrder = "PostDraw"
>>>>> cnres at mpFillDrawOrder = "PreDraw"
>>>>> ; cnres at mpOutlineBoundarySets = "National"
>>>>> cnres at mpOutlineBoundarySets = "Allboundaries"
>>>>> cnres at mpUSStateLineDashPattern = 2
>>>>> cnres at mpOutlineOn = True
>>>>> cnres at mpDataBaseVersion = "MediumRes"
>>>>> cnres at mpDataSetName = "Earth..4" ; U.S. counties
>>>>> ;cnres at mpGridAndLimbOn = True
>>>>> ;cnres at mpGridLineColor = "Grey"
>>>>> cnres at mpFillColors = (/"transparent","transparent",
>>>>> "gray","transparent"/)
>>>>> cnres at pmTickMarkDisplayMode = "Always"
>>>>> cnres at tiMainString = "Domain 1 @ 27km"
>>>>> cnres at tiDeltaF = 3.3
>>>>> cnres at tfDoNDCOverlay = True
>>>>>
>>>>> cnres at gsnDraw = False ; don't draw
>>>>> cnres at gsnFrame = False ; don't advance
>>>>> frame
>>>>>
>>>>> ; cnres at vpWidthF = 0.40
>>>>> cnres at vpHeightF = 0.20
>>>>>
>>>>> ;---Create smooth contour plot
>>>>> plot_wrf_d01 = gsn_csm_contour_map(wks,pm25_avg,cnres)
>>>>>
>>>>>
>>>>> delete(pm25init)
>>>>> delete(pm25sum)
>>>>> delete(pm25_avg)
>>>>> delete(s)
>>>>> delete(lat2d)
>>>>> delete(lon2d)
>>>>> ;-----------------------------------------------------------
>>>>> -----------
>>>>> ; Recreate similar plot, but by using filled markers drawn over a map.
>>>>> ;-----------------------------------------------------------
>>>>> -----------
>>>>> fname = "surfacedata_12-31_Octmean_improved_nomissingval.txt"
>>>>> lines = asciiread(fname,-1,"string")
>>>>> lon = tofloat(str_get_field(lines(:),2," "))
>>>>> lat = tofloat(str_get_field(lines(:),3," "))
>>>>> pm25 = tofloat(str_get_field(lines(:),4," "))
>>>>>
>>>>>
>>>>> ;*****************************************
>>>>> ; add black circles over obs data
>>>>> ;*****************************************
>>>>> polyres = True ; poly marker mods desired
>>>>> polyres at gsMarkerIndex = 4 ; choose circle as polymarker
>>>>> polyres at gsMarkerSizeF = 5 ; select size to avoid streaking
>>>>> polyres at gsMarkerColor = (/"black"/) ; choose color
>>>>> polyres at gsMarkerThicknessF = 2.0
>>>>> tabish1=gsn_add_polymarker(wks,plot_wrf_d01,lon,lat,polyres) ;
>>>>> draw polymarkers
>>>>>
>>>>> ;---Add colored markers to the map
>>>>> add_obs_markers_to_map(wks,plot_wrf_d01,levels,colormap,pm25
>>>>> ,lat,lon)
>>>>>
>>>>> ; draw(plot_wrf)
>>>>> ; frame(wks)
>>>>>
>>>>> ;***********************************************
>>>>> ; NOW REPEATING THE SAME ROUTINE FOR D03
>>>>> ;***********************************************
>>>>>
>>>>>
>>>>> DATADir = "/data2/tabish/control-run-so4-ECMWF/"
>>>>> FILES = systemfunc (" ls -1 " + DATADir + "wrfout_d03_2014-10* ")
>>>>> numFILES = dimsizes(FILES)
>>>>>
>>>>> s=1
>>>>> a = addfile(FILES(0)+".nc","r"); THIS IS JUST FOR INITIALIZATION OF
>>>>> PM25 ARRAY, IT WILL BE SUBSTRACTED FROM THE SUM IN THE END
>>>>> pm25init = a->PM2_5_DRY(15,0,:,:)
>>>>> pm25sum = pm25init
>>>>> times = wrf_user_getvar(a,"times",-1) ; get all times in the file
>>>>> ntimes = dimsizes(times)
>>>>> do it = 16,ntimes-1,1 ; TIME LOOP
>>>>> s=s+1
>>>>> print("Working on time: " + times(it) )
>>>>> pm25sum = pm25sum + a->PM2_5_DRY(it,0,:,:)
>>>>> end do ; END OF TIME LOOP
>>>>>
>>>>> do ifil = 1,numFILES-2 ; FILE LOOP
>>>>> a = addfile(FILES(ifil)+".nc","r") ; Open the next file
>>>>> times = wrf_user_getvar(a,"times",-1) ; get all times in the file
>>>>> ntimes = dimsizes(times)
>>>>> do it = 0,ntimes-1,1 ; TIME LOOP
>>>>> s=s+1
>>>>> print("Working on time: " + times(it) )
>>>>> pm25sum = pm25sum + a->PM2_5_DRY(it,0,:,:)
>>>>> end do ; END OF TIME LOOP
>>>>> end do
>>>>> pm25_avg= pm25sum/s
>>>>> ;pm25_avg at description = "NO2 conc in ppbv"
>>>>>
>>>>> lat2d = wrf_user_getvar(a,"XLAT",it) ; latitude/longitude
>>>>> lon2d = wrf_user_getvar(a,"XLONG",it)
>>>>>
>>>>> pm25_avg at lat2d = lat2d ; for plotting
>>>>> pm25_avg at lon2d = lon2d
>>>>> res at mpLimitMode = "Corners" ; choose range of map
>>>>> res at mpLeftCornerLatF = 36.05806
>>>>> res at mpLeftCornerLonF = 113.3356
>>>>> res at mpRightCornerLatF = 42.4514
>>>>> res at mpRightCornerLonF = 120.2583
>>>>> cnres at mpLimitMode = "Corners" ; choose range of map
>>>>> cnres at mpLeftCornerLatF = 36.05806
>>>>> cnres at mpLeftCornerLonF = 113.3356
>>>>> cnres at mpRightCornerLatF = 42.4514
>>>>> cnres at mpRightCornerLonF = 120.2583
>>>>> cnres at tiMainString = "Domain 3 @ 3km"
>>>>> cnres at vpKeepAspect = True
>>>>> cnres at vpHeightF = 0.20
>>>>>
>>>>> ;---Create smooth contour plot
>>>>> plot_wrf_d03 = gsn_csm_contour_map(wks,pm25_avg,cnres)
>>>>> ;*****************************************
>>>>> ; add black circles over obs data
>>>>> ;*****************************************
>>>>> polyres = True ; poly marker mods desired
>>>>> polyres at gsMarkerIndex = 4 ; choose circle as polymarker
>>>>> polyres at gsMarkerSizeF = 5 ; select size to avoid streaking
>>>>> polyres at gsMarkerColor = (/"black"/) ; choose color
>>>>> polyres at gsMarkerThicknessF = 2.0
>>>>> tabish3=gsn_add_polymarker(wks,plot_wrf_d03,lon,lat,polyres) ; draw
>>>>> polymarkers
>>>>>
>>>>> ;---Add colored markers to the map
>>>>> add_obs_markers_to_map(wks,plot_wrf_d03,levels,colormap,pm25
>>>>> ,lat,lon)
>>>>>
>>>>>
>>>>> ;---Panel both plots for comparison.
>>>>> pres = True
>>>>> pres at gsnMaximize = True
>>>>> pres at gsnPanelLabelBar = True
>>>>> pres at pmLabelBarWidthF = 0.8
>>>>> pres at lbLabelFontHeightF = 0.01
>>>>> pres at gsnFrame = False
>>>>> pres at gsnPanelBottom = 0.05 ; add space at bottom
>>>>> gsn_panel(wks,(/plot_wrf_d01,plot_wrf_d03/),(/1,2/),pres)
>>>>>
>>>>> ; Draw a text string at the bottom
>>>>> txres = True
>>>>> txres at txFontHeightF = 0.012
>>>>> gsn_text_ndc(wks,"PM2.5 in ug/m3",0.5,0.28,txres)
>>>>> frame(wks)
>>>>> ; Maximize plots in frame.
>>>>> ; psres = True
>>>>> ; maximize_output(wks,psres) ; calls draw and frame for you
>>>>>
>>>>>
>>>>> end
>>>>>
>>>>>
>>>>> Your help will be greatly appreciated.
>>>>>
>>>>> Thanks
>>>>>
>>>>> Tabish
>>>>>
>>>>>
>>>>> Tabish U Ansari
>>>>> PhD student, Lancaster Environment Center
>>>>> Lancaster Univeristy
>>>>> Bailrigg, Lancaster,
>>>>> LA1 4YW, United Kingdom
>>>>>
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> ncl-talk at ucar.edu
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://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>
>>>>
>>>
>>>
>>
>>
>> --
>> 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>
>>
>
>
--
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: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180515/5003c775/attachment.html>
More information about the ncl-talk
mailing list