Suggestion for annotation arrow clipping

Mpl 1.0.0

The way Annotation.draw (in text.py) is implemented, if an annotation
is created with an annotation point (x,y) and text located at (tx,ty)
and then the you pan around on the graph such that (x,y) is no longer
visible, the annotation suddenly disappears.

I would suggest the following modification to Annotation.draw in
text.py. All it does is set a clip box so that the annotation and
arrow is still drawn, but the arrow is clipped at the axes boundary.
It is a much nicer effect than the annotation disappearing. I have
made this modification in my source locally, and it works very well,
but I thought I would suggest here for inclusion into the main code
base.

Modified lines are marked with a CHANGEME. It is only a four line change.

    @allow_rasterization
    def draw(self, renderer):
        """
        Draw the :class:`Annotation` object to the given *renderer*.
        """

        if renderer is not None:
            self._renderer = renderer
        if not self.get_visible(): return

        xy_pixel = self._get_position_xy(renderer)

        #if not self._check_xy(renderer, xy_pixel): CHANGEME (commented out)
        # return
CHANGEME (commented out)

        self._update_position_xytext(renderer, xy_pixel)
        self.update_bbox_position_size(renderer)

        if self.arrow is not None:
            if self.arrow.figure is None and self.figure is not None:
                self.arrow.figure = self.figure
            self.arrow.set_clip_box(self.axes.bbox) # CHANGEME (new line)
            self.arrow.draw(renderer)

        if self.arrow_patch is not None:
            if self.arrow_patch.figure is None and self.figure is not None:
                self.arrow_patch.figure = self.figure
            self.arrow_patch.set_clip_box(self.axes.bbox) # CHANGEME (new line)
            self.arrow_patch.draw(renderer)

        Text.draw(self, renderer)

···

--
Daniel Hyams
dhyams@...287...

Can you explain more explicitly why you think this behavior is better?
For example, what is the point of annotating something if that
something is not visible?
Also, annotating texts are often placed outside of axes area. I don't
think clipping out the arrow is a good idea in this case.

Just in case, this is just a default behavior. You can override this
behavior without changing the mpl source code.

Regards,

-JJ

···

On Mon, Sep 12, 2011 at 3:20 AM, Daniel Hyams <dhyams@...287...> wrote:

I would suggest the following modification to Annotation.draw in
text.py. All it does is set a clip box so that the annotation and
arrow is still drawn, but the arrow is clipped at the axes boundary.
It is a much nicer effect than the annotation disappearing. I have
made this modification in my source locally, and it works very well,
but I thought I would suggest here for inclusion into the main code
base.

You are correct JJ; the annotation_clip=False attribute was exactly
what I was after, but somehow missed it in the docs :(.

···

On Wed, Sep 14, 2011 at 9:09 PM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

On Mon, Sep 12, 2011 at 3:20 AM, Daniel Hyams <dhyams@...287...> wrote:

I would suggest the following modification to Annotation.draw in
text.py. All it does is set a clip box so that the annotation and
arrow is still drawn, but the arrow is clipped at the axes boundary.
It is a much nicer effect than the annotation disappearing. I have
made this modification in my source locally, and it works very well,
but I thought I would suggest here for inclusion into the main code
base.

Can you explain more explicitly why you think this behavior is better?
For example, what is the point of annotating something if that
something is not visible?
Also, annotating texts are often placed outside of axes area. I don't
think clipping out the arrow is a good idea in this case.

Just in case, this is just a default behavior. You can override this
behavior without changing the mpl source code.

Regards,

-JJ

--
Daniel Hyams
dhyams@...287...