Hi Ben,

On Thu, Feb 10, 2011 at 5:06 PM, Benjamin Root <ben.r...@ou.edu> wrote:
> On Thu, Feb 10, 2011 at 1:38 PM, Matthew Turk <matthewt...@gmail.com> wrote:
>>
>> Hi there,
>>
>> I'm plotting some images in latitude/longitude space.  These are
>> images generated using the HEALpix method for discretizing the sphere,
>> but I have resampled them to a regular grid of phi, theta, and the
>> resultant image is contained in a variable img.  This is a fully-self
>> contained snippet:
>>
>> import matplotlib.figure
>> import matplotlib.backends.backend_agg
>> import numpy
>> from numpy import pi
>>
>> img = numpy.random.random((800, 800))
>> fig = matplotlib.figure.Figure((10, 4.9))
>> ax = fig.add_subplot(1,1,1,projection='mollweide')
>> image = ax.imshow(img, extent=(-pi,pi,-pi/2,pi/2), clip_on=False,
>> aspect=0.5)
>> cb = fig.colorbar(image, orientation='horizontal')
>> canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
>> canvas.print_figure("hi.png")
>>
>> This makes a very nice looking figure, basically as expected: a black
>> oval outline for the map projection with the image inside it, the
>> lat/lon axes identified, etc.  What I'm running into here is that I
>> would like to fiddle with the size of the figure, to adjust the
>> whitespace and the position of the colorbar and so on, but any
>> adjustment to the height of the figure instantiation, for instance:
>>
>> fig = matplotlib.figure.Figure((10, 4.9))
>>
>> (and the rest unchanged) results in the black oval, the axes, but the
>> image content is completely blank.  Is this a bug, or just a subtlety
>> I'm missing?
>>
>> Thanks for any ideas!
>>
>> Best,
>>
>> Matt
>>
>
> I am curious, why are you saving the figure using canvas.print_figure()?
> How is it different from fig.savefig()?  If you, for some reason, must use
> canvas.print_figure(), then it seems like you are creating a new canvas from
> the figure  (I don't know, maybe it grabs figure's existing canvas
> object?).  In other words, you could just simply do:
>
> fig.savefig("hi.png")

Maybe I'm doing something wrong here, but in the example script I gave
the figure does not have a canvas object affiliated with it; it's set
to None until I execute this operation:

canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)

At that point, fig.canvas is not None, and is the same canvas that I
just created:

>>> print fig.canvas
None
>>> canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(fig)
>>> canvas.print_figure("hi.png")
>>> fig.canvas
<matplotlib.backends.backend_agg.FigureCanvasAgg instance at 0x10263d3b0>
>>> canvas is fig.canvas
True

>
> or, if you must use canvas.print_figure(), you could do:
>
> fig.canvas.print_figure()
>
> instead of the two lines you have right now.
>
> See if that makes a difference.

Unfortunately it didn't end up making a difference.  The image is
still printed, with colorbar, with lat/lon lines, but no image in the
center of the black oval for the projection.

Thanks,

Matt

>
> Ben Root
>
>

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to