FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Backport PR #31075 on branch v3.10.x (Fix remove method for figure title and xy-labels) by meeseeksmachine · Pull Request #31078 · matplotlib/matplotlib · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions lib/matplotlib/figure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,17 @@ def _suplabels(self, t, info, **kwargs):
else:
suplab = self.text(x, y, t, **kwargs)
setattr(self, info['name'], suplab)
suplab._remove_method = functools.partial(self._remove_suplabel,
name=info['name'])

suplab._autopos = autopos
self.stale = True
return suplab

def _remove_suplabel(self, label, name):
self.texts.remove(label)
setattr(self, name, None)

@_docstring.Substitution(x0=0.5, y0=0.98, name='super title', ha='center',
va='top', rc='title')
@_docstring.copy(_suplabels)
Expand Down
22 changes: 22 additions & 0 deletions lib/matplotlib/tests/test_figure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,28 @@ def test_get_suptitle_supxlabel_supylabel():
assert fig.get_supylabel() == 'supylabel'


def test_remove_suptitle_supxlabel_supylabel():
fig = plt.figure()

title = fig.suptitle('suptitle')
xlabel = fig.supxlabel('supxlabel')
ylabel = fig.supylabel('supylabel')

assert len(fig.texts) == 3
assert fig._suptitle is not None
assert fig._supxlabel is not None
assert fig._supylabel is not None

title.remove()
assert fig._suptitle is None
xlabel.remove()
assert fig._supxlabel is None
ylabel.remove()
assert fig._supylabel is None

assert not fig.texts


@image_comparison(['alpha_background'],
# only test png and svg. The PDF output appears correct,
# but Ghostscript does not preserve the background color.
Expand Down
Loading

Back | FazBrowse Home | New Git URL