[ncl-talk] How can I get a full page plot ?

Alan Brammer abrammer at albany.edu
Tue May 23 12:04:53 MDT 2017


There a couple tricks to do this, and I don’t think a complete example anywhere so not sure where it would go though. 


Key resources to really fill a png.
res at gsnMaximize = True
res at gsnBoxMargin = 0          ;; took a lot of digging to find this one. https://www.ncl.ucar.edu/Document/Graphics/Resources/gsn.shtml#gsnBoxMargin


Key things to remember, 
>	"because NCL always draws its graphics to a square canvas, the PNG image will be resized to a square, using the largest of the two values, if you give it non-square values.” 
		https://www.ncl.ucar.edu/Applications/resize.shtml <https://www.ncl.ucar.edu/Applications/resize.shtml> 


So if you want it 1366 wide set both wkWidth and wkHeight to 1366. 
That will fill the png horizontally but leave you with white space at the top and bottom.  You can then use “-trim" or “-shave 0x261”  (assuming an 844 image height) to crop that border top and bottom.  Don’t think there’s a way to produce rectangular plots without white space being included.   

I put a couple of lines at the bottom that should work out the white space and trim it off by itself.  


Good luck, 

Alan


e.g. with different map coords so different shave numbers. 

wkst = "png"
wkst at wkWidth = 1366 
wkst at wkHeight = wkst at wkWidth 
outputname = "filled_png"

wks = gsn_open_wks(wkst,outputname)
mpres := True
mpres at mpLimitMode       = "Corners"     ;;; use a cropped area just to identify	the edge of the plot. 
mpres at mpProjection      = "mercator"
mpres at mpPerimOn         = False         
mpres at mpLeftCornerLonF  = -100
mpres at mpRightCornerLonF = 100
mpres at mpRightCornerLatF = 60
mpres at mpLeftCornerLatF  = 0

mpres at tmXTOn  = False		;;; Here and below are the only ones that actually matter
mpres at tmXBOn = False		
mpres at tmYROn = False
mpres at tmYLOn = False

mpres at gsnMaximize= True		;;; 
mpres at gsnBoxMargin = 0		;;;  this one is the key one to really fill the png
plot = gsn_csm_map(wks, mpres)

getvalues plot
    "vpHeightF": vpHF
    "vpWidthF": vpWF   ;; should be 1.
end getvalues
 
image_height = 1366*vpHF
half_margin = floor(0.5* (wkst at wkHeight-image_height) )

;system("convert -shave 0x"+half_margin+" "+outputname+"."+wkst+" shaved.png")
;; or
system("mogrify -shave 0x"+half_margin+" "+outputname+"."+wkst)  ;; sister to convert, replaces original image





##############################
Alan Brammer,
Post-Doc Researcher

Department of Atmospheric and Environmental Sciences,
University at Albany, State University of New York, Albany, NY, 12222
abrammer at albany.edu
##############################




> On 22 May 2017, at 12:31, Roussan <rousslucas at gmail.com> wrote:
> 
> Hello,
> I would like to plot contours in full page at a given size (1366 x 844),
> with no margins, no white spaces, just the plot at this dimmension.
> Is it possible, or do I have to use imagemaick or graphicsmagick to crop the output image ?
> (I have disabled titles and labels.)
> 
>  Here is the piece of code :
> 
>   waveheight = fin->HTSGW_P0_L1_GLL0
>   delete(waveheight at long_name)
>   delete(waveheight at units)
> 
>   wavedir    = fin->DIRPW_P0_L1_GLL0
>   delete(wavedir at long_name)
>   delete(wavedir at units)
> 
>   wks_type = "png"
>   wks_type at wkWidth = 1366
>   wks_type at wkHeight = 844
>   wks  = gsn_open_wks(wks_type,outfile)
>   
>   vres                           = True
>   vres at vcRefAnnoOn = False
> 
>   res  = True
>   res at gsnMaximize     = True
>   res at lbLabelBarOn    = False
>   res at lbTitleOn            = False
>   vres at lbLabelBarOn   = False
>   vres at lbTitleOn           = False
> 
>   plot = gsn_csm_contour_map(wks,waveheight,res)
>   plot_ov = gsn_csm_vector_scalar(wks, udir(:,:), vdir(:,:),waveheight,vres)
> 
>   overlay(plot,plot_ov)                  ; overlay the U-wind plot on the temperature plot
> 
>   draw(plot)                                  ; draw the temperature plot (with the U-wind plot overlaid)
>   frame(wks)                                 ; advance the frame
> 
> 
> 
> 
> You will can see what I can achieve in attachement.
> Thank you in advance
> Ross.
> <out.png>_______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170523/f8c7ac9f/attachment.html 


More information about the ncl-talk mailing list