Title: savefig and path.py · Issue #11306 · matplotlib/matplotlib · GitHub
Open Graph Title: savefig and path.py · Issue #11306 · matplotlib/matplotlib
X Title: savefig and path.py · Issue #11306 · matplotlib/matplotlib
Description: Bug report Bug summary Matplotlib now supports Path-like objets like pathlib.Path, but it broke the support for Path objects from path.py. Code for reproduction import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111)...
Open Graph Description: Bug report Bug summary Matplotlib now supports Path-like objets like pathlib.Path, but it broke the support for Path objects from path.py. Code for reproduction import matplotlib.pyplot as plt fig ...
X Description: Bug report Bug summary Matplotlib now supports Path-like objets like pathlib.Path, but it broke the support for Path objects from path.py. Code for reproduction import matplotlib.pyplot as plt fig ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/11306
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"savefig and path.py","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nMatplotlib now supports Path-like objets like `pathlib.Path`, but it broke the support for `Path` objects from path.py.\r\n\r\n**Code for reproduction**\r\n\r\n\u003c!--A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required--\u003e\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n\r\nfig = plt.figure()\r\nax = fig.add_subplot(111)\r\nax.plot([1, 2, 3])\r\n\r\n# Works with a string\r\nfig.savefig(\"toto.png\")\r\n\r\n# Works with pathlib\r\nfrom pathlib import Path\r\nfig.savefig(Path(\"toto.png\"))\r\n\r\n# Fails with path.py\r\nfrom path import Path\r\nfig.savefig(Path(\"toto.png\"))\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\u003c!--The output produced by the above code, which may be a screenshot, console output, etc.--\u003e\r\n\r\n```\r\nTraceback (most recent call last):\r\n File \"mplbug.py\", line 20, in \u003cmodule\u003e\r\n fig.savefig(Path(\"toto.png\"))\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\figure.py\", line 2035, in savefig\r\n self.canvas.print_figure(fname, **kwargs)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\backends\\backend_qt5agg.py\", line 94, in print_figure\r\n super(FigureCanvasQTAgg, self).print_figure(*args, **kwargs)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\backend_bases.py\", line 2263, in print_figure\r\n **kwargs)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\backends\\backend_agg.py\", line 526, in print_png\r\n with cbook.open_file_cm(filename_or_obj, \"wb\") as fh:\r\n File \"D:\\data\\Miniconda3\\lib\\contextlib.py\", line 81, in __enter__\r\n return next(self.gen)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\cbook\\__init__.py\", line 624, in open_file_cm\r\n fh, opened = to_filehandle(path_or_file, mode, True, encoding)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\cbook\\__init__.py\", line 598, in to_filehandle\r\n flag=flag, return_opened=return_opened, encoding=encoding)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\cbook\\__init__.py\", line 598, in to_filehandle\r\n flag=flag, return_opened=return_opened, encoding=encoding)\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\cbook\\__init__.py\", line 598, in to_filehandle\r\n flag=flag, return_opened=return_opened, encoding=encoding)\r\n [Previous line repeated 972 more times]\r\n File \"D:\\data\\Miniconda3\\lib\\site-packages\\matplotlib\\cbook\\__init__.py\", line 595, in to_filehandle\r\n if hasattr(os, \"PathLike\") and isinstance(fname, os.PathLike):\r\n File \"D:\\data\\Miniconda3\\lib\\abc.py\", line 184, in __instancecheck__\r\n if subclass in cls._abc_cache:\r\n File \"D:\\data\\Miniconda3\\lib\\_weakrefset.py\", line 75, in __contains__\r\n return wr in self.data\r\nRecursionError: maximum recursion depth exceeded in comparison\r\n```\r\n\r\n**Expected outcome**\r\n\r\nNo traceback.\r\n\r\n**Matplotlib version**\r\n\u003c!--Please specify your platform and versions of the relevant libraries you are using:--\u003e\r\n * Operating system: Linux (Ubuntu) and Windows 7\r\n * Matplotlib version: 2.2.2 from Anaconda\r\n * Matplotlib backend (`print(matplotlib.get_backend())`): Qt5Agg\r\n * Python version: 3.6\r\n * Jupyter version (if applicable):\r\n * Other libraries: path.py\r\n\r\n\u003c!--Please tell us how you installed matplotlib and python e.g., from source, pip, conda--\u003e\r\n\u003c!--If you installed from conda, please specify which channel you used if not the default--\u003e\r\n\r\nFor information, Path objects from path.py inherit from string and are PathLike objects.","author":{"url":"https://github.com/Nodd","@type":"Person","name":"Nodd"},"datePublished":"2018-05-25T07:43:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/11306/matplotlib/issues/11306"}
| 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:6050e738-ebdb-84c6-fdd9-63cf1dfc0244 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E250:3A3C76:4B38D1:6C444C:6A55E117 |
| html-safe-nonce | d9096bf5e3f1dd0beeefd001f88dc593b3a8fa8a39f8e65193f1fcdc19c148b7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjUwOjNBM0M3Njo0QjM4RDE6NkM0NDRDOjZBNTVFMTE3IiwidmlzaXRvcl9pZCI6IjgwMDg1ODc2NzYyMzEyNjI0ODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 754063b993e60ba60d1ed8d527c548162637e00318c198af200cbf9dbc6abfb2 |
| hovercard-subject-tag | issue:326415041 |
| 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/11306/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3cce27415cff484c03c6025535e503404c5480a22bf69ea4cf578072d6b287a5/matplotlib/matplotlib/issues/11306 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3cce27415cff484c03c6025535e503404c5480a22bf69ea4cf578072d6b287a5/matplotlib/matplotlib/issues/11306 |
| og:image:alt | Bug report Bug summary Matplotlib now supports Path-like objets like pathlib.Path, but it broke the support for Path objects from path.py. Code for reproduction import matplotlib.pyplot as plt fig ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Nodd |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | 3725c7f9b2a6e3a27ef57c5aed13428c0f65e045 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width