All, Motivated in part by an old patch (1233294) submitted
> to sourceforge by Nikolai Hlubek, I took a look at how
> aspect ratio is handled in mpl, and concluded it wasn't
> quite right:
Just a few quick comments since I haven't had a chance to look over
this in any detail.
> 1) The aspect='preserve' kwarg in image caused the image to
> retain its aspect ratio only with some resize events, not
> with all. The implementation in the image.py code does not
> look right to me.
> Therefore I have reworked the aspect-handling code in
> axes.py, and I think it is working reasonably well. Indeed,
> I don't see any remaining need for an "aspect" kwarg in
> image.py, and I would like to take it out unless someone
> raises an objection.
The aspect handling of images has been known to be broken from the
early days, but in those days we didn't even have aspect='equal'
functionality, and so adding preserved aspect ratio proved to
daunting. Noone has revisited the issue (until now) since Mark Bakkar
finally (mostly) got proper aspect handling in the axes. So your
observations are on target, and the image aspect handling is an
anachronism that everyone quickly learned to ignore.
> def set_aspect(self, aspect='auto', fixLimits=None,
> aspect_adjusts='position'): """ aspect: 'auto' - automatic;
> fill position rectangle with data 'normal' - same as 'auto';
> deprecated 'equal' - same scaling from data to plot units
> for x and y A - a circle will be stretched such that the
> height is A times the width. aspect=1 is the same as
> aspect='equal'.
Mark Bakkar wrote most of the aspect handling for the axes, and so he
can response most intelligently to these changes. You should send him
your original post since he may not be on this list. He's CCd above.
> One question: is there an easy way to automatically trigger
> a redraw in an interactive backend (e.g. ipython with
> gtkagg) at the end of the set_aspect() method, for example?
> The way it works now is that one can make a plot, call the
> set_aspect() method on the resulting axes object, and the
> result will appear as soon as the window is manipulated with
> the mouse; but this manipulation is needed to trigger a
> redraw.
You should be able to do something like
if rcParams['interactive']:
self.figure.canvas.draw()
where self is an Axes instance. Untested, but I think it is valid
across backends.
Thanks for the submission -- I look forward to testing it.
JDH