I have added a bbox support for "restore_region", but I'm afraid that this feature is not well tested. And I guess what you find is, unfortunately, a bug. While I'll try to push the changes to the svn tomorrow, you may try to monkey-patch with following code.
from matplotlib.transforms import Bbox, BboxBase from matplotlib.backends.backend_agg import RendererAgg def restore_region(self, region, bbox=None, xy=None): if bbox is not None or xy is not None: rx, ry, width, height = region.get_extents() if bbox is None: x1, y1, x2, y2 = region.get_extents() elif isinstance(bbox, BboxBase): x1, y1, x2, y2 = bbox.extents else: x1, y1, x2, y2 = bbox if xy is None: ox, oy = rx, ry else: ox, oy = xy self._renderer.restore_region2(region, x1, height-y2+ry, x2, height-y1+ry, ox, oy) else: self._renderer.restore_region(region) RendererAgg.restore_region = restore_region But, again, the code is not well tested and there could be another bug (or even this patch may introduce a new bug). So, see how it works and let know of any problem. However, while matplotlib does support some animation, I think you 'd better turn to another tool if you need an efficiency, Regards, -JJ On Sun, Feb 14, 2010 at 2:18 PM, Brendan Barnwell <brenb...@brenbarn.net> wrote: > Brendan Barnwell wrote: >> I'm trying to find the quickest way to erase a rectangular area of >> the figure canvas. I tried using canvas.restore_region with the >> optional bbox argument, but there seems to be some mismatch between >> the measurement units of the saved buffer object and the currently >> shown data. For instance, if I have a Text object on my plot, I tried >> this: >> >> bbox = g.text.get_window_extent() >> canvas.restore_region(background, bbox) >> >> . . . but it does not correctly block out the text. (The restored >> rectangle from the background appears elsewhere on the axes.) How can >> I convert the buffer coordinates to the coordinates of the the >> displayed plot? > > I'm sorry to bump my own post, but I would really appreciate some > help with this. I've been wrestling with it for a couple days now, > and I cannot figure out how the coordinate system of the saved canvas > is related to the axes coordinates. I have found that with > bbox.transformed(ax.transData) I can at least get the coordinates > scaled to fit on the axes, but they are still offset in position from > where the box actually appears on the canvas. I can't figure out how > to compute this offset. > > By playing around with the coordinates manually, for instance, I've > found that adjusting x by -52 and y by 21 appears to line up the > canvas with the axes, but I can't see where these numbers -52 and 21 > would come from. My saved canvas buffer's get_extents() method > returns (65, 50, 586, 443), so I thought that the appropriate offsets > would be 65 and 50, but that doesn't work. > > So, what coordinates (x1, y1, x2, y2) do I need to use in > canvas.restore_region(savedBuffer, (x1, y1, x2, y2)) in order to > restore precisely the area of canvas occupied by a patch drawn at axis > coordinates (a1, b1, a2, b2)? > > Thanks? > -- > Brendan Barnwell > "Do not follow where the path may lead. Go, instead, where there is > no path, and leave a trail." > --author unknown > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users