Skip to content

Commit e392b59

Browse files
authored
Merge pull request #28468 from meeseeksmachine/auto-backport-of-pr-28465-on-v3.9.x
Backport PR #28465 on branch v3.9.x (Fix pickling of SubFigures)
2 parents 1f0e4c4 + 14711fa commit e392b59

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,6 @@ def __init__(self, parent, subplotspec, *,
22242224
self.subplotpars = parent.subplotpars
22252225
self.dpi_scale_trans = parent.dpi_scale_trans
22262226
self._axobservers = parent._axobservers
2227-
self.canvas = parent.canvas
22282227
self.transFigure = parent.transFigure
22292228
self.bbox_relative = Bbox.null()
22302229
self._redo_transform_rel_fig()
@@ -2241,6 +2240,10 @@ def __init__(self, parent, subplotspec, *,
22412240
self._set_artist_props(self.patch)
22422241
self.patch.set_antialiased(False)
22432242

2243+
@property
2244+
def canvas(self):
2245+
return self._parent.canvas
2246+
22442247
@property
22452248
def dpi(self):
22462249
return self._parent.dpi

lib/matplotlib/figure.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ class SubFigure(FigureBase):
263263
figure: Figure
264264
subplotpars: SubplotParams
265265
dpi_scale_trans: Affine2D
266-
canvas: FigureCanvasBase
267266
transFigure: Transform
268267
bbox_relative: Bbox
269268
figbbox: BboxBase
@@ -282,6 +281,8 @@ class SubFigure(FigureBase):
282281
**kwargs
283282
) -> None: ...
284283
@property
284+
def canvas(self) -> FigureCanvasBase: ...
285+
@property
285286
def dpi(self) -> float: ...
286287
@dpi.setter
287288
def dpi(self, value: float) -> None: ...

lib/matplotlib/tests/test_pickle.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def _generate_complete_test_figure(fig_ref):
9393
plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4, label='$-.5 x$')
9494
plt.legend(draggable=True)
9595

96+
# Ensure subfigure parenting works.
97+
subfigs = fig_ref.subfigures(2)
98+
subfigs[0].subplots(1, 2)
99+
subfigs[1].subplots(1, 2)
100+
96101
fig_ref.align_ylabels() # Test handling of _align_label_groups Groupers.
97102

98103

0 commit comments

Comments
 (0)
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