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

Skip to content

Commit 9091975

Browse files
authored
Merge pull request #16207 from meeseeksmachine/auto-backport-of-pr-16189-on-v3.2.x
Backport PR #16189 on branch v3.2.x (MNT: set default canvas when un-pickling)
2 parents 1c1b8a5 + d497f85 commit 9091975

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ def __setstate__(self, state):
20262026

20272027
# re-initialise some of the unstored state information
20282028
self._axobservers = []
2029-
self.canvas = None
2029+
FigureCanvasBase(self) # Set self.canvas.
20302030
self._layoutbox = None
20312031

20322032
if restore_to_pylab:

lib/matplotlib/tests/test_pickle.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from matplotlib.dates import rrulewrapper
1111
import matplotlib.pyplot as plt
1212
import matplotlib.transforms as mtransforms
13+
import matplotlib.figure as mfigure
1314

1415

1516
def test_simple():
@@ -194,3 +195,13 @@ def test_shared():
194195
@pytest.mark.parametrize("cmap", cm.cmap_d.values())
195196
def test_cmap(cmap):
196197
pickle.dumps(cmap)
198+
199+
200+
def test_unpickle_canvas():
201+
fig = mfigure.Figure()
202+
assert fig.canvas is not None
203+
out = BytesIO()
204+
pickle.dump(fig, out)
205+
out.seek(0)
206+
fig2 = pickle.load(out)
207+
assert fig2.canvas is not None

0 commit comments

Comments
 (0)