Skip to content

Commit

Permalink
Fix pickling of SubFigures
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Jun 26, 2024
1 parent 57cd5eb commit 555cdbc
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 @@ -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()
Expand All @@ -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
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 555cdbc

Please sign in to comment.