Skip to content

Commit

Permalink
Merge pull request matplotlib#28468 from meeseeksmachine/auto-backpor…
Browse files Browse the repository at this point in the history
…t-of-pr-28465-on-v3.9.x

Backport PR matplotlib#28465 on branch v3.9.x (Fix pickling of SubFigures)
  • Loading branch information
tacaswell authored Jun 26, 2024
2 parents 1f0e4c4 + 14711fa commit e392b59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2224,7 +2224,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()
Expand All @@ -2241,6 +2240,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
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/figure.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ class SubFigure(FigureBase):
figure: Figure
subplotpars: SubplotParams
dpi_scale_trans: Affine2D
canvas: FigureCanvasBase
transFigure: Transform
bbox_relative: Bbox
figbbox: BboxBase
Expand All @@ -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: ...
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down

0 comments on commit e392b59

Please sign in to comment.