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

Skip to content

Backport PR #28465 on branch v3.9.x (Fix pickling of SubFigures) #28468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading