8000 Fix staletxt by tacaswell · Pull Request #5486 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix staletxt #5486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
8000 Loading
Diff view
Diff view
8000
8 changes: 2 additions & 6 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,16 +609,14 @@ def text(self, x, y, s, fontdict=None,
else:
t = mtext.Text(
x=x, y=y, text=s)
self._set_artist_props(t)

t.update(default)
if fontdict is not None:
t.update(fontdict)
t.update(kwargs)
self.texts.append(t)
t._remove_method = lambda h: self.texts.remove(h)

t.set_clip_path(self.patch)
self._add_text(t)
return t

@docstring.dedent_interpd
Expand Down Expand Up @@ -674,11 +672,9 @@ def annotate(self, *args, **kwargs):
"""
a = mtext.Annotation(*args, **kwargs)
a.set_transform(mtransforms.IdentityTransform())
self._set_artist_props(a)
if 'clip_on' in kwargs:
a.set_clip_path(self.patch)
self.texts.append(a)
a._remove_method = lambda h: self.texts.remove(h)
self._add_text(a)
return a

#### Lines and spans
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ def add_artist(self, a):
self._set_artist_props(a)
a.set_clip_path(self.patch)
a._remove_method = lambda h: self.artists.remove(h)
self.stale = True
return a

def add_collection(self, collection, autolim=True):
Expand All @@ -1672,6 +1673,7 @@ def add_collection(self, collection, autolim=True):
self.update_datalim(collection.get_datalim(self.transData))

collection._remove_method = lambda h: self.collections.remove(h)
self.stale = True
return collection

def add_image(self, image):
Expand All @@ -1683,6 +1685,7 @@ def add_image(self, image):
self._set_artist_props(image)
self.images.append(image)
image._remove_method = lambda h: self.images.remove(h)
self.stale = True
return image

def add_line(self, line):
Expand All @@ -1701,8 +1704,19 @@ def add_line(self, line):
line.set_label('_line%d' % len(self.lines))
self.lines.append(line)
line._remove_method = lambda h: self.lines.remove(h)
self.stale = True
return line

def _add_text(self, txt):
"""

"""
self._set_artist_props(txt)
self.texts.append(txt)
txt._remove_method = lambda h: self.texts.remove(h)
self.stale = True
return txt

def _update_line_limits(self, line):
"""
Figures out the data limit of the given line, updating self.dataLim.
Expand Down
24 changes: 24 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,27 @@ def test_annotation_negative_fig_coords():
xytext=[-50, 100], textcoords='figure pixels',
xy=[-50, 100], xycoords='figure pixels', fontsize=32,
va='top')


@cleanup
def test_text_stale():
fig, (ax1, ax2) = plt.subplots(1, 2)
plt.draw_all()
assert not ax1.stale
assert not ax2.stale
assert not fig.stale

txt1 = ax1.text(.5, .5, 'aardvark')
assert ax1.stale
assert txt1.stale
assert fig.stale

ann1 = ax2.annotate('aardvark', xy=[.5, .5])
assert ax2.stale
assert ann1.stale
assert fig.stale

plt.draw_all()
assert not ax1.stale
assert not ax2.stale
assert not fig.stale
0