Skip to content

Commit b5f00d5

Browse files
QuLogictacaswell
authored andcommitted
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 3301248)
1 parent 4d02bc9 commit b5f00d5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,6 +2886,9 @@ def __getstate__(self):
28862886
# Set cached renderer to None -- it can't be pickled.
28872887
state["_cachedRenderer"] = None
28882888

2889+
# discard any changes to the dpi due to pixel ratio changes
2890+
state["_dpi"] = state.get('_original_dpi', state['_dpi'])
2891+
28892892
# add version information to the state
28902893
state['__mpl_version__'] = mpl.__version__
28912894

lib/matplotlib/tests/test_figure.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
import io
33
from pathlib import Path
4+
import pickle
45
import platform
56
from threading import Timer
67
from types import SimpleNamespace
@@ -1360,3 +1361,11 @@ def test_kwargs_pass():
13601361

13611362
assert fig.get_label() == 'whole Figure'
13621363
assert sub_fig.get_label() == 'sub figure'
1364+
1365+
1366+
def test_unpickle_with_device_pixel_ratio():
1367+
fig = Figure(dpi=42)
1368+
fig.canvas._set_device_pixel_ratio(7)
1369+
assert fig.dpi == 42*7
1370+
fig2 = pickle.loads(pickle.dumps(fig))
1371+
assert fig2.dpi == 42

0 commit comments

Comments
 (0)
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