On Thu, May 14, 2009 at 2:03 PM, Jae-Joon Lee <lee.j.joon@gmail.com> wrote:
On Thu, May 14, 2009 at 4:36 AM, Ben Coppin <coppin@gmail.com> wrote:
> Hi,
>
> I've added annotations to a graph I am producing using matplotlib. The
> annotations work fine, but when you zoom and pan, the annotations move off
> the edge of the chart and are still visible while they're in the main TK
> window. Does anyone know of a way to make the annotations disappear when
> they move off the edge of the chart?

Currently, there is no support for this. However, a monkey patching
can be a quick solution for now.


from matplotlib.text import Annotation

def draw(self, renderer):
   x, y = self.xy
   x, y = self._get_xy(x, y, self.xycoords)
   if not self.axes.bbox.contains(x, y):
       return

   self.draw_real(renderer)

Annotation.draw_real = Annotation.draw
Annotation.draw = draw

ann = annotate("test", (0.5, 0.5), xytext=(0.6, 0.6),
              arrowprops=dict(arrowstyle="->"))


I think this should be the default behavior (with optionally turned
off). If other developers don't object, i'll try to push this feature
into the svn.

You can't do this using the existing support for clipping artists?  I was planning on cooking up an example that did just that, but haven't yet found the time.

Ryan

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
Sent from Norman, Oklahoma, United States