From 555cdbc2b2bbf3a1c89b54e842958414b172f752 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 26 Jun 2024 03:10:15 -0400 Subject: [PATCH] Fix pickling of SubFigures --- lib/matplotlib/figure.py | 5 ++++- lib/matplotlib/figure.pyi | 3 ++- lib/matplotlib/tests/test_pickle.py | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 9139b2ed262f..7bb06814f389 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2227,7 +2227,6 @@ def __init__(self, parent, subplotspec, *, self.subplotpars = parent.subplotpars self.dpi_scale_trans = parent.dpi_scale_trans self._axobservers = parent._axobservers - self.canvas = parent.canvas self.transFigure = parent.transFigure self.bbox_relative = Bbox.null() self._redo_transform_rel_fig() @@ -2244,6 +2243,10 @@ def __init__(self, parent, subplotspec, *, self._set_artist_props(self.patch) self.patch.set_antialiased(False) + @property + def canvas(self): + return self._parent.canvas + @property def dpi(self): return self._parent.dpi diff --git a/lib/matplotlib/figure.pyi b/lib/matplotlib/figure.pyi index 21de9159d56c..b079312695c1 100644 --- a/lib/matplotlib/figure.pyi +++ b/lib/matplotlib/figure.pyi @@ -263,7 +263,6 @@ class SubFigure(FigureBase): figure: Figure subplotpars: SubplotParams dpi_scale_trans: Affine2D - canvas: FigureCanvasBase transFigure: Transform bbox_relative: Bbox figbbox: BboxBase @@ -282,6 +281,8 @@ class SubFigure(FigureBase): **kwargs ) -> None: ... @property + def canvas(self) -> FigureCanvasBase: ... + @property def dpi(self) -> float: ... @dpi.setter def dpi(self, value: float) -> None: ... diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index 7e7ccc14bf8f..0cba4f392035 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -93,6 +93,11 @@ def _generate_complete_test_figure(fig_ref): plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4, label='$-.5 x$') plt.legend(draggable=True) + # Ensure subfigure parenting works. + subfigs = fig_ref.subfigures(2) + subfigs[0].subplots(1, 2) + subfigs[1].subplots(1, 2) + fig_ref.align_ylabels() # Test handling of _align_label_groups Groupers. 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