Re: Layout of plot with PyNGL

From: Daran Rife <drife_at_nyahnyahspammersnyahnyah>
Date: Wed, 1 Apr 2009 14:34:43 -0600

Hi Dave,

This is very helpful. I was definitely thinking from the perspective
of a page layout, not the NDC viewport space using in PyNGL. I've
modified my script and now the entire plot fits within the viewport.
For fun, I've attached the plot.

For my specific case, is there an easy way to maximize the entire
contents of the viewport, eliminating most of the white space. The
data are a bit hard to see. I am familiar with the Ngl.maximiz_plot
function, and the nglMaximize resource, but don't think they can be
used for my case.

Thanks again for your help. I do appreciate it.

Daran

--


--
On Apr 1, 2009, at 2:15 PM, David Brown wrote:
> Hi Daran,
> Yes it sure would be easier if it were possible to use the panelling  
> code with wmbarbmap, but since it is not, let me try to suggest an  
> approach that will manually approximate what the panelling and plot- 
> maximizing code does.
>
> First, it's important to realize that the viewspace for all PyNGL  
> graphics is a unit square that goes from 0 - 1 along both axes. So I  
> would suggest first drawing to the X11workstation, which only shows  
> the unit square, and adjusting your plots until all the graphics are  
> visible in the X window.  Then determine the NDC coordinates of
> the min and max X and Y extents of the graphics. In the case of a  
> group of plots such as the sample you have attached, you might have  
> values such as:
>   left x: 0.3 right x: 0.7 bottom y: 0.05 top y: 0.95
>
> In the X workstation this means a lot of white space on the left and  
> right and not much on the bottom and top. Now imagine taking this  
> unit square and adjusting the size and position such that the  
> graphics fill as much of an 8.5 x 11 sheet of paper as possible.  
> This implies that the left and right edges of the square will be off  
> the sheet of paper, while the top and bottom are at the edges of the  
> printable extent of the paper (this is assumed to be 0.5 inches  
> inside the paper edges -- a good approximation for typical  
> printers). This can be achieved by modifying the values of the PDF  
> workstation resources wkDevice[Upper | Lower][X | Y].
>
> These resources have units of 1/72 of an inch. Since your plot will  
> have a portrait orientation, the origin of the page and of the PyNGL  
> viewspace are both in the lower left corner. This makes the  
> calculation a bit simpler. The default values of these resources are  
> designed to center the complete unit square on the plot. But in your  
> case you want to make the Y axis as big as possible without losing  
> anything along the X axis.  Basically you need to compare the aspect  
> ratio of your plot to the aspect ratio of the drawing surface. This  
> will determine which axis limits the ultimate size of the plot.  
> Using the example numbers, the plot has a ratio of (Y/X) 0.9 / 0.4  
> or 2.25 while the paper ratio (subtracting the margin) is 10 / 7.5  
> or 1.333. This make the Y axis the limiting factor, so it should be  
> made as big as possible.
>
> So you would set wkDeviceLowerY to 36 and wkDeviceUpperY to 756 (792  
> - 36 ). That means the Y axis extent is 720 or 10 inches. Now since  
> the PyNGL viewspace is always square and your graphics are centered  
> along the X axis, you simply need to subtract and add half this  
> amount from the center of the drawing space X axis:
> (8.5 * 72) / 2 = 306 ;  5 * 72 = 360 ;  so you would set  
> wkDeviceLowerX to -54 (306 - 360) and wkDeviceUpperX to 666 (306 +  
> 360).
>
> If you are plotting in landscape mode, the calculations are  bit  
> more complicated because the origin of the PyNGL viewspace is placed  
> such that the PyNGL viewspace origin is  at the upper left of the  
> PDF coordinate system and the PyNGL X Axis increases in the negative  
> direction of the PDF Y axis. But the principles are the same.
>
> I hope this is not too confusing an explanation.
> -dave
>
>
>
> On Apr 1, 2009, at 9:01 AM, Daran L. Rife wrote:
>
>> Hello,
>>
>> I'm creating a multi-panel plot with PyNGL, and
>> having a Dickens of a time getting all the panel
>> to fit within the viewport, while simultaneously
>> using the maximum amount of real estate on a PDF
>> workstation. The end result is heaps of "white
>> space" surrounding my panels, and the bottom two
>> panels partially lying outside the viewport. I
>> have attached the resulting plot.
>>
>> For this particular plot, I am unable to use the
>> Ngl.panel function, which automatically lays out
>> the panels, fitting them within the viewport while
>> simultaneously using as much of the real estate
>> on the PDF page as possible. The reason I cannot
>> use Ngl.panel is that I am using the Ngl.wmbarbmap
>> to draw my station data. Ngl.wmbarbmap cannot be
>> used in conjunction with Ngl.panel.
>>
>> I have done extensive searching of the excellent
>> online documentation and user forums, and have
>> experimented with various PyNGL resource settings,
>> all to no avail.
>>
>> I would be grateful if one of the PyNGL gurus could
>> help me sort out the proper PyNGL calls needed to
>> achieve my desired plot.
>>
>> I have placed the script and data on my FTP site:
>>
>> ftp://ftp.rap.ucar.edu/incoming/irap/drife/
>>
>> The main script is plot_soms_panel.py, and is called with the
>> following arguments:
>>
>>> ./plot_soms_panel.py orig_som.cod TERRAIN_DOMAIN3.WSMR.nc  
>>> stns_for_gmt
>>
>> I'm running this from an OS X (Intel) Leopard box, using NumPy
>> 1.2.1, and PyNGL version 1.3.0b1, and Python 2.5.0.
>>
>>
>> Thanks in advance for your help.
>>
>>
>> Daran
>>
>>
>> <test.pdf>_______________________________________________
>> pyngl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk

_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk

Received on Wed Apr 01 2009 - 14:34:43 MDT

This archive was generated by hypermail 2.2.0 : Tue Apr 07 2009 - 10:04:30 MDT