Title: Figure is unpicklable after `savefig` · Issue #6870 · matplotlib/matplotlib · GitHub
Open Graph Title: Figure is unpicklable after `savefig` · Issue #6870 · matplotlib/matplotlib
X Title: Figure is unpicklable after `savefig` · Issue #6870 · matplotlib/matplotlib
Description: import matplotlib.pyplot as plt import pickle from io import BytesIO def test_pickle_after_savefig(): fig = plt.figure() fig.add_subplot(111) for fmt in ['pdf', 'png', 'svg']: fig.savefig(BytesIO(), format=fmt) try: pickle.dump(fig, Byte...
Open Graph Description: import matplotlib.pyplot as plt import pickle from io import BytesIO def test_pickle_after_savefig(): fig = plt.figure() fig.add_subplot(111) for fmt in ['pdf', 'png', 'svg']: fig.savefig(BytesIO()...
X Description: import matplotlib.pyplot as plt import pickle from io import BytesIO def test_pickle_after_savefig(): fig = plt.figure() fig.add_subplot(111) for fmt in ['pdf', 'png', 'svg'...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/6870
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Figure is unpicklable after `savefig`","articleBody":"``` python\nimport matplotlib.pyplot as plt\nimport pickle\nfrom io import BytesIO\n\ndef test_pickle_after_savefig():\n fig = plt.figure()\n fig.add_subplot(111)\n for fmt in ['pdf', 'png', 'svg']:\n fig.savefig(BytesIO(), format=fmt)\n try:\n pickle.dump(fig, BytesIO())\n except:\n print('Unpickable after \"%s\"' % fmt)\n raise\n\ntest_pickle_after_savefig()\n```\n\n```\n\u003epython test_pickle_after_savefig.py\nUnpickable after \"svg\"\nTraceback (most recent call last):\n File \"test_pickle_after_savefig.py\", line 16, in \u003cmodule\u003e\n test_pickle_after_savefig()\n File \"test_pickle_after_savefig.py\", line 11, in test_pickle_after_savefig\n pickle.dump(fig, BytesIO())\nTypeError: cannot serialize '_io.TextIOWrapper' object\n```\n\nI think those warnings from pytest are maybe related:\n\n```\n\u003epy.test -n 4 lib/matplotlib/tests/test_backend_svg.py::test_fill_black_with_alpha\n============================= test session starts =============================\nplatform win32 -- Python 3.5.2, pytest-2.9.2, py-1.4.31, pluggy-0.3.1\nrootdir: C:\\Working\\Repositories\\matplotlib, inifile: pytest.ini\nplugins: xdist-1.14\ngw0 [1] / gw1 [1] / gw2 [1] / gw3 [1]\nscheduling tests via LoadScheduling\n.sys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=0 mode='r' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=1 mode='w' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=0 mode='r' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=0 mode='r' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=1 mode='w' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=1 mode='w' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=0 mode='r' encoding='cp866'\u003e\nsys:1: ResourceWarning: unclosed file \u003c_io.TextIOWrapper name=1 mode='w' encoding='cp866'\u003e\n```\n\nWith a file name pickle fails in the pdf backend (and svg too):\n\n``` python\nimport matplotlib.pylab as plt\nimport pickle\nfrom io import BytesIO\n\ndef test_pickle_after_savefig2():\n fig = plt.figure()\n fig.add_subplot(111)\n for fmt in ['pdf', 'png', 'svg']:\n fig.savefig('test.%s' % fmt, format=fmt)\n try:\n pickle.dump(fig, BytesIO())\n except:\n print('Unpickable format is \"%s\"' % fmt)\n raise\n\ntest_pickle_after_savefig2()\n```\n\n```\n\u003epython test_pickle_after_savefig2.py\nUnpickable format is \"pdf\"\nTraceback (most recent call last):\n File \"test_pickle_after_savefig2.py\", line 16, in \u003cmodule\u003e\n test_pickle_after_savefig()\n File \"test_pickle_after_savefig2.py\", line 11, in test_pickle_after_savefig\n pickle.dump(fig, BytesIO())\nTypeError: cannot serialize '_io.BufferedWriter' object\n```\n","author":{"url":"https://github.com/Kojoley","@type":"Person","name":"Kojoley"},"datePublished":"2016-07-31T18:35:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/6870/matplotlib/issues/6870"}
| 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:e8df2e05-af09-495a-0f4c-21fb833f2aac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5AC:22A568:46B1CC:5DD05B:6A52789A |
| html-safe-nonce | 118b9fa74a1d84f4f9fa4917522918db708e00c95ddc36e40596e110935b4c66 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUFDOjIyQTU2ODo0NkIxQ0M6NUREMDVCOjZBNTI3ODlBIiwidmlzaXRvcl9pZCI6Ijc5NTc0MTcxMDA4NTkwNDYwNDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f4a056290d3096db7a3621f72b9e24135d6fd251d2b7e934a88551aa876845ef |
| hovercard-subject-tag | issue:168531558 |
| 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/6870/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a43ac18fe22cb99cd68228b3758248548266d05df18b8cc8494a6fcb7f0c75d9/matplotlib/matplotlib/issues/6870 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a43ac18fe22cb99cd68228b3758248548266d05df18b8cc8494a6fcb7f0c75d9/matplotlib/matplotlib/issues/6870 |
| og:image:alt | import matplotlib.pyplot as plt import pickle from io import BytesIO def test_pickle_after_savefig(): fig = plt.figure() fig.add_subplot(111) for fmt in ['pdf', 'png', 'svg']: fig.savefig(BytesIO()... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Kojoley |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width