X Tutup
Skip to content
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.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/figure.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,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
X Tutup