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

Skip to content

Commit bbb0d01

Browse files
tacaswellrcomer
authored andcommitted
Merge pull request #28397 from rcomer/subfigure-stale
Backport PR #28397: FIX: stale root Figure when adding/updating subfigures (cherry picked from commit d347c32)
1 parent 826575f commit bbb0d01

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,8 @@ def add_subfigure(self, subplotspec, **kwargs):
16331633
sf = SubFigure(self, subplotspec, **kwargs)
16341634
self.subfigs += [sf]
16351635
sf._remove_method = self.subfigs.remove
1636+
sf.stale_callback = _stale_figure_callback
1637+
self.stale = True
16361638
return sf
16371639

16381640
def sca(self, a):

lib/matplotlib/tests/test_figure.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,3 +1733,27 @@ def test_warn_colorbar_mismatch():
17331733
subfig3_1.colorbar(im3_2) # should not warn
17341734
with pytest.warns(UserWarning, match="different Figure"):
17351735
subfig3_1.colorbar(im4_1)
1736+
1737+
1738+
def test_subfigure_stale_propagation():
1739+
fig = plt.figure()
1740+
1741+
fig.draw_without_rendering()
1742+
assert not fig.stale
1743+
1744+
sfig1 = fig.subfigures()
1745+
assert fig.stale
1746+
1747+
fig.draw_without_rendering()
1748+
assert not fig.stale
1749+
assert not sfig1.stale
1750+
1751+
sfig2 = sfig1.subfigures()
1752+
assert fig.stale
1753+
1754+
fig.draw_without_rendering()
1755+
assert not fig.stale
1756+
assert not sfig2.stale
1757+
1758+
sfig2.stale = True
1759+
assert fig.stale

0 commit comments

Comments
 (0)