imshow: set_extent

I just committed this patch in svn. The additional code was lifted from
imshow, to reshape the axes along with the image.


Index: lib/matplotlib/


On Wednesday 15 August 2007 05:05:51 pm you wrote:

Darren Dale wrote:
> I'm doing something along the lines of:
> create an initial image with imshow
> add a colorbar
> update the image using the image's set_data method
> Occassionally, the extents of the image will change. How do I handle
> that? The only place I can find to set the extents is in the call to
> imshow. The resulting image has a get_extents, but not a setter. I can't
> make repeated calls to imshow, because the new image isnt coupled to the
> colorbar. I can't figure out how to couple the colorbar to the new image,
> and I dont know how to get rid of the old colorbar to clear space for a
> new one.


Try directly setting the extent via the _extent attribute of the image
object. If that works and doesn't cause any new problems, then we can
add a trivial set_extent method.

--- lib/matplotlib/ (revision 3709)
+++ lib/matplotlib/ (working copy)
@@ -236,6 +236,18 @@
         # by mistake.

+ def set_extent(self, extent):
+ """extent is data axes (left, right, bottom, top) for making image
+ """
+ self._extent = extent
+ xmin, xmax, ymin, ymax = extent
+ corners = (xmin, ymin), (xmax, ymax)
+ self.axes.update_datalim(corners)
+ if self.axes._autoscaleon:
+ self.axes.set_xlim((xmin, xmax))
+ self.axes.set_ylim((ymin, ymax))

     def get_interpolation(self):