Skip to content

Annotation text bbox calculated incorrectly in matplotlib>=1.4.3? #4139

Closed

Description

@joferkington

Prior to matplotlib 1.4.3, text bounding boxes created with annotate did not include the connection arrow. Starting with 1.4.3 and continuing up to the current HEAD, the bbox includes the connection arrow.

As an example:

import matplotlib.pyplot as plt
import matplotlib

fig, ax = plt.subplots()

ax.annotate('Matplotlib {}'.format(matplotlib.__version__),
            xy=(0.1, 0.1), xytext=(50, 50), size=20,
            xycoords='data', textcoords='offset points',
            bbox=dict(alpha=0.5, fc='yellow'),
            arrowprops=dict(arrowstyle='->'))

plt.show()

mpl1 4 2

mpl1 4 3

mpl_github

This may be related to #4012?

Activity

  1. jenshnielsen commented on Feb 21, 2015

    @jenshnielsen
    Member

    I think this is likely due to #4023 which was merged as 26c7d65

  2. added this to the milestone on Feb 21, 2015
  3. added
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Feb 21, 2015
  4. tacaswell commented on Feb 21, 2015

    @tacaswell
    Member

    I agree with @jenshnielsen's diagnosis. Someplace a call to self.get_window_extent()needs to be changed toText.get_window_extent(self)`.

  5. cimarronm commented on Feb 22, 2015

    @cimarronm
    Contributor

    It is related to #4023. The issue is that the Annotation draw method calls the Text draw method to draw the text box portion. Inside that, it calls bbox_artist from the patches modules which then calls get_window_extent of the instance.

  6. efiring commented on Mar 1, 2015

    @efiring
    Member

    There's even more: if boxstyle='square' is added to the bbox dictionary kwarg in the example, so that a FancyBboxPatch is drawn, then the filled region is correct, but the arrow is not clipped correctly.

  7. removed
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Mar 1, 2015
  8. tacaswell commented on Mar 1, 2015

    @tacaswell
    Member

    The clipping is related to #4012 I think.

  9. self-assigned this
    on Mar 1, 2015
  10. modified the milestones: , on Oct 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions