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")

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.

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