From b5f00d5272129c7890b7813d9a8083c1aac9c3fc Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 22 Jul 2022 16:00:08 -0400 Subject: [PATCH] Backport PR #23476: FIX: reset to original DPI in getstate Merge pull request #23476 from tacaswell/fix/unpickle_dpi FIX: reset to original DPI in getstate (cherry picked from commit 330124862b46dc003ff3e38427efcc9000b9d7ab) --- lib/matplotlib/figure.py | 3 +++ lib/matplotlib/tests/test_figure.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 44f62436fb6d..d114801ea12f 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2886,6 +2886,9 @@ def __getstate__(self): # Set cached renderer to None -- it can't be pickled. state["_cachedRenderer"] = None + # discard any changes to the dpi due to pixel ratio changes + state["_dpi"] = state.get('_original_dpi', state['_dpi']) + # add version information to the state state['__mpl_version__'] = mpl.__version__ diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 05d1d2ae82c4..966f127df6ff 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -1,6 +1,7 @@ from datetime import datetime import io from pathlib import Path +import pickle import platform from threading import Timer from types import SimpleNamespace @@ -1360,3 +1361,11 @@ def test_kwargs_pass(): assert fig.get_label() == 'whole Figure' assert sub_fig.get_label() == 'sub figure' + + +def test_unpickle_with_device_pixel_ratio(): + fig = Figure(dpi=42) + fig.canvas._set_device_pixel_ratio(7) + assert fig.dpi == 42*7 + fig2 = pickle.loads(pickle.dumps(fig)) + assert fig2.dpi == 42 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