Choosing optimal figure width/height automatically

Hello,

I'm stuck trying to find a solution to the following problem.

I'd like to show an array using imshow preserving the 1:1 aspect ratio
of its pixels. At the same time, I would like the axes to fit around
the image tightly.

Is there some way to, for example, choose a certain figure width, and
have the height chosen automatically to the optimal value?

Thanks,
Christoph

I particularly like using the figaspect() function:

http://matplotlib.org/api/figure_api.html?highlight=figaspect#matplotlib.figure.figaspect

The example usage there needs to be updated (it assumes the pylab mode
which imports everything in pyplot into the global namespace). But it
should be accessible like so:

import matplotlib.pyplot as plt

w, h = plt.figaspect(2)

It isn't perfect, but for its simplicity, it gets it mostly right.

Cheers!
Ben Root

ยทยทยท

On Thu, Oct 17, 2013 at 8:20 AM, Christoph Groth <cwg@...4122...> wrote:

Hello,

I'm stuck trying to find a solution to the following problem.

I'd like to show an array using imshow preserving the 1:1 aspect ratio
of its pixels. At the same time, I would like the axes to fit around
the image tightly.

Is there some way to, for example, choose a certain figure width, and
have the height chosen automatically to the optimal value?

Thanks,
Christoph