Skip to content

Commit d20ea49

Browse files
committed
MNT: set default canvas when un-pickling
In 380c531 / #12450 we set the default canvas on Figure `__init__` to FigureCanvasBase but were still setting it to `None` in `__setstate__`.
1 parent 56d0828 commit d20ea49

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/matplotlib/figure.py

+1-1
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

+11
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)