From 583e1d91b5cbcc764ccf87cb27737bf71370d2a9 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 21 Jun 2020 17:17:19 +0200 Subject: [PATCH] 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. --- 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy