From bbb0d01bfa333746c77c4490164e9e3682fd56b2 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 26 Jun 2024 17:03:20 -0400 Subject: [PATCH] Merge pull request #28397 from rcomer/subfigure-stale Backport PR #28397: FIX: stale root Figure when adding/updating subfigures (cherry picked from commit d347c3227f8de8a99aa327390fee619310452a96) --- lib/matplotlib/figure.py | 2 ++ lib/matplotlib/tests/test_figure.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index d75ff527a008..0d939190a0a9 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -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): diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 58aecd3dea8b..6e6daa77062d 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy