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

Skip to content

Commit af49c1b

Browse files
authored
Merge pull request #16189 from tacaswell/fix_unpickled_canvas
MNT: set default canvas when un-pickling
2 parents 0013547 + d20ea49 commit af49c1b

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
@@ -1999,7 +1999,7 @@ def __setstate__(self, state):
19991999

20002000
# re-initialise some of the unstored state information
20012001
self._axobservers = []
2002-
self.canvas = None
2002+
FigureCanvasBase(self) # Set self.canvas.
20032003
self._layoutbox = None
20042004

20052005
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)