From 4e5019e36f056766e818346c874bbfe7cd822a2a Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 1 Jun 2022 12:30:25 +0200 Subject: [PATCH] Make sure SubFigure has _cachedRenderer --- lib/matplotlib/figure.py | 8 ++++++++ lib/matplotlib/tests/test_contour.py | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 0b8ad9828b3d..d0d9f8e695dc 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2060,6 +2060,14 @@ def dpi(self): def dpi(self, value): self._parent.dpi = value + @property + def _cachedRenderer(self): + return self._parent._cachedRenderer + + @_cachedRenderer.setter + def _cachedRenderer(self, renderer): + self._parent._cachedRenderer = renderer + def _redo_transform_rel_fig(self, bbox=None): """ Make the transSubfigure bbox relative to Figure transform. diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index bb7dd3630b97..5f3f961971e8 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -585,3 +585,23 @@ def test_all_algorithms(): ax.contourf(x, y, z, algorithm=algorithm) ax.contour(x, y, z, algorithm=algorithm, colors='k') ax.set_title(algorithm) + + +def test_subfigure_clabel(): + # Smoke test for gh#23173 + delta = 0.025 + x = np.arange(-3.0, 3.0, delta) + y = np.arange(-2.0, 2.0, delta) + X, Y = np.meshgrid(x, y) + Z1 = np.exp(-(X**2) - Y**2) + Z2 = np.exp(-((X - 1) ** 2) - (Y - 1) ** 2) + Z = (Z1 - Z2) * 2 + + fig = plt.figure() + figs = fig.subfigures(nrows=1, ncols=2) + + for f in figs: + ax = f.subplots() + CS = ax.contour(X, Y, Z) + ax.clabel(CS, inline=True, fontsize=10) + ax.set_title("Simplest default with labels")