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

Skip to content

Commit 6a343de

Browse files
committed
Fix pickling of SubFigures
1 parent 57cd5eb commit 6a343de

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
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/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)