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

Skip to content

Commit d56572f

Browse files
authored
Merge pull request #28465 from QuLogic/fix-subfigure-pickle
Fix pickling of SubFigures
2 parents 57cd5eb + 555cdbc commit d56572f

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
@@ -2227,7 +2227,6 @@ def __init__(self, parent, subplotspec, *,
22272227
self.subplotpars = parent.subplotpars
22282228
self.dpi_scale_trans = parent.dpi_scale_trans
22292229
self._axobservers = parent._axobservers
2230-
self.canvas = parent.canvas
22312230
self.transFigure = parent.transFigure
22322231
self.bbox_relative = Bbox.null()
22332232
self._redo_transform_rel_fig()
@@ -2244,6 +2243,10 @@ def __init__(self, parent, subplotspec, *,
22442243
self._set_artist_props(self.patch)
22452244
self.patch.set_antialiased(False)
22462245

2246+
@property
2247+
def canvas(self):
2248+
return self._parent.canvas
2249+
22472250
@property
22482251
def dpi(self):
22492252
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)