Title: [Bug]: Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). · Issue #32053 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). · Issue #32053 · matplotlib/matplotlib
X Title: [Bug]: Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). · Issue #32053 · matplotlib/matplotlib
Description: Bug summary Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). Code for reproduction import pickle import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize...
Open Graph Description: Bug summary Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). Code for reproduction import pickle import matplotlib.pypl...
X Description: Bug summary Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). Code for reproduction import pickle import matplotlib.pypl...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32053
X: @github
Domain: Github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi().","articleBody":"### Bug summary\n\nPickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via `Figure.set_dpi()`.\n\n### Code for reproduction\n\n```python\nimport pickle\nimport matplotlib.pyplot as plt\n\nfig, ax = plt.subplots(figsize=(5, 3), dpi=100)\nax.plot([0, 1, 2, 3], [0, 1, 4, 9], label=\"quadratic\")\nax.set_title(\"DPI round trip\")\nax.legend()\n\nprint(\"Original DPI:\", fig.get_dpi())\nfig.set_dpi(150)\nprint(\"DPI after public set_dpi(150):\", fig.get_dpi())\n\nrestored = pickle.loads(pickle.dumps(fig))\nprint(\"DPI after pickle round trip:\", restored.get_dpi())\nprint(\"Line count:\", len(restored.axes[0].lines))\n\nplt.close(fig)\nplt.close(restored)\n```\n\n### Actual outcome\n\n```text\nOriginal DPI: 100\nDPI after public set_dpi(150): 150\nDPI after pickle round trip: 100\nLine count: 1\n```\n\n### Expected outcome\n\nThe explicitly configured DPI should be preserved across pickle round-tripping:\n\n```text\nOriginal DPI: 100\nDPI after public set_dpi(150): 150\nDPI after pickle round trip: 150\nLine count: 1\n```\n\n### Additional information\n\nThis regression was introduced by [PR #23476](https://github.com/matplotlib/matplotlib/pull/23476).\n\nThe new code replaces the current DPI with `_original_dpi` whenever that state entry exists. This correctly discards a transient DPI change made for a canvas device-pixel ratio, but `_original_dpi` is established independently of later public calls to `Figure.set_dpi()`. Consequently, a figure intentionally changed from 100 to 150 DPI is serialized with 100 DPI instead of 150 DPI, causing a loss of public figure state.\n\n### Operating system\n\nLinux\n\n### Matplotlib Version\n\n3.11.0\n\n### Matplotlib Backend\n\nagg\n\n### Python version\n\n3.11.13\n\n### Jupyter version\n\nN/A\n\n### Installation\n\nN/A","author":{"url":"https://github.com/RippleTester","@type":"Person","name":"RippleTester"},"datePublished":"2026-07-17T10:07:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/32053/matplotlib/issues/32053"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9236e9ee-bf37-2ddd-8077-380b90608685 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BFE8:E9480:1B5649:24CEF8:6A62834C |
| html-safe-nonce | d4478e9181f275409f5d9e0171bc21867f8035a6dea30b1ead1da23cbf7af36e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkU4OkU5NDgwOjFCNTY0OToyNENFRjg6NkE2MjgzNEMiLCJ2aXNpdG9yX2lkIjoiMTU0MDM4ODY5NTM1MDM0NjU3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | eeb061dff08291d89571a081011a97f3b2ba93482eaf2ec1a87838c5c8d376af |
| hovercard-subject-tag | issue:4910296880 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/32053/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fd4345d735bfab0a2a00e8d41309a7120318ce76606b9e2eb797c867f131390b/matplotlib/matplotlib/issues/32053 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fd4345d735bfab0a2a00e8d41309a7120318ce76606b9e2eb797c867f131390b/matplotlib/matplotlib/issues/32053 |
| og:image:alt | Bug summary Pickle round-tripping a figure incorrectly restores its original DPI instead of a DPI explicitly changed via Figure.set_dpi(). Code for reproduction import pickle import matplotlib.pypl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RippleTester |
| hostname | github.com |
| expected-hostname | github.com |
| None | 834f5745a0905171956ffda6a4bdff25548a80194071fe4a15acaa5b349a60a0 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4d79f1b99472a521fc5fb66e9fdc3ce742937dff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width