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

Skip to content

Commit 583e1d9

Browse files
committed
Keep cachedRenderer as None when pickling Figure.
`Figure.__init__` sets cachedRenderer to None, so it's awkward that pickling and unpickling a figure completely removes the attribute, causing obscure AttributeErrors.
1 parent 193b8f6 commit 583e1d9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/matplotlib/figure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,8 +2108,10 @@ def __getstate__(self):
21082108
# The canvas cannot currently be pickled, but this has the benefit
21092109
# of meaning that a figure can be detached from one canvas, and
21102110
# re-attached to another.
2111-
for attr_to_pop in ('canvas', '_cachedRenderer'):
2112-
state.pop(attr_to_pop, None)
2111+
state.pop("canvas")
2112+
2113+
# Set cached renderer to None -- it can't be pickled.
2114+
state["_cachedRenderer"] = None
21132115

21142116
# add version information to the state
21152117
state['__mpl_version__'] = _mpl_version

0 commit comments

Comments
 (0)