Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0e7e69

Browse files
committed
Fix remove method for figure title and xy-labels
1 parent eb7c4ce commit d0e7e69

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

lib/matplotlib/figure.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,13 @@ def _suplabels(self, t, info, **kwargs):
376376
else:
377377
suplab = self.text(x, y, t, **kwargs)
378378
setattr(self, info['name'], suplab)
379+
380+
def remove_method(t):
381+
self.texts.remove(t)
382+
setattr(self, info['name'], None)
383+
384+
suplab._remove_method = remove_method
385+
379386
suplab._autopos = autopos
380387
self.stale = True
381388
return suplab

lib/matplotlib/tests/test_figure.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,28 @@ def test_get_suptitle_supxlabel_supylabel():
365365
assert fig.get_supylabel() == 'supylabel'
366366

367367

368+
def test_remove_suptitle_supxlabel_supylabel():
369+
fig = plt.figure()
370+
371+
title = fig.suptitle('suptitle')
372+
xlabel = fig.supxlabel('supxlabel')
373+
ylabel = fig.supylabel('supylabel')
374+
375+
assert len(fig.texts) == 3
376+
assert fig._suptitle is not None
377+
assert fig._supxlabel is not None
378+
assert fig._supylabel is not None
379+
380+
title.remove()
381+
assert fig._suptitle is None
382+
xlabel.remove()
383+
assert fig._supxlabel is None
384+
ylabel.remove()
385+
assert fig._supylabel is None
386+
387+
assert not fig.texts
388+
389+
368390
@image_comparison(['alpha_background'],
369391
# only test png and svg. The PDF output appears correct,
370392
# but Ghostscript does not preserve the background color.

0 commit comments

Comments
 (0)