From f7ea2b3a85c81acb5bb6939cc9947cb073838e0b Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 22 Jun 2020 11:00:00 -0400 Subject: [PATCH] Backport PR #17705: Keep cachedRenderer as None when pickling Figure. --- lib/matplotlib/figure.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 8bd42a9cba98..ce8e71f54a53 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2108,8 +2108,10 @@ def __getstate__(self): # The canvas cannot currently be pickled, but this has the benefit # of meaning that a figure can be detached from one canvas, and # re-attached to another. - for attr_to_pop in ('canvas', '_cachedRenderer'): - state.pop(attr_to_pop, None) + state.pop("canvas") + + # Set cached renderer to None -- it can't be pickled. + state["_cachedRenderer"] = None # add version information to the state state['__mpl_version__'] = _mpl_version