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

Skip to content

Backport PR #28397 (FIX: stale root Figure when adding/updating subfigures) #28479

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 1 commit into from
Jun 27, 2024
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
2 changes: 2 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,8 @@ def add_subfigure(self, subplotspec, **kwargs):
sf = SubFigure(self, subplotspec, **kwargs)
self.subfigs += [sf]
sf._remove_method = self.subfigs.remove
sf.stale_callback = _stale_figure_callback
self.stale = True
return sf

def sca(self, a):
Expand Down
24 changes: 24 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,3 +1733,27 @@ def test_warn_colorbar_mismatch():
subfig3_1.colorbar(im3_2) # should not warn
with pytest.warns(UserWarning, match="different Figure"):
subfig3_1.colorbar(im4_1)


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

fig.draw_without_rendering()
assert not fig.stale

sfig1 = fig.subfigures()
assert fig.stale

fig.draw_without_rendering()
assert not fig.stale
assert not sfig1.stale

sfig2 = sfig1.subfigures()
assert fig.stale

fig.draw_without_rendering()
assert not fig.stale
assert not sfig2.stale

sfig2.stale = True
assert fig.stale
Loading