I just tested this code on a second box with different
> mpl defaults and found a few minor issues. They are now
> fixed in this new attached version.
Hi Fernando, this is a very useful submission that solves a recurrent
problem people have. So useful, that I factored out the hard part
(getting the figure size right) into a separate function figaspect
which lives in matplotlib.figure so it could be reused in other
contexts. The rest is easy, and lives in pylab.matshow, which calls
figaspect to do the heavy lifting.
A few comments
* you also need to be sure that the axes have the same width and
height. Since the width and height are expressed in fractions of
the figure size, you can use any width and height you want and get
the right answer as long as they are the same, since the figure
width and height have the right aspect ration. The default axes --
subplot(111) -- have slightly different values for w and h. This
is fixed in CVS with
w,h = figaspect(arr)
fig = figure(figsize=(w,h))
ax = fig.add_axes([0.0, 0.05, 0.8, 0.8])
* To get the labels on top, you do
ax.xaxis.tick_top() # this turns off tick bottom and turns on tick top
likewise, there are yaxis functions tick_left and tick_right. This
is also in CVS
* I return a (fig, ax, im) tuple
Give it a test drive and let me know what you think (pylab revision
1.34 or later in CVS)
JDH