Title: [Bug]: Saving a figure with bbox_inches="tight" fails after inset_axes · Issue #26468 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Saving a figure with bbox_inches="tight" fails after inset_axes · Issue #26468 · matplotlib/matplotlib
X Title: [Bug]: Saving a figure with bbox_inches="tight" fails after inset_axes · Issue #26468 · matplotlib/matplotlib
Description: Bug summary After using inset_axes in mpl 3.7.2, savefig fails if bbox_inches is set to "tight". This does not fail in 3.7.1. Code for reproduction import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.inset_locator import inset_a...
Open Graph Description: Bug summary After using inset_axes in mpl 3.7.2, savefig fails if bbox_inches is set to "tight". This does not fail in 3.7.1. Code for reproduction import matplotlib.pyplot as plt from mpl_toolkits...
X Description: Bug summary After using inset_axes in mpl 3.7.2, savefig fails if bbox_inches is set to "tight". This does not fail in 3.7.1. Code for reproduction import matplotlib.pyplot as plt from mp...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/26468
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Saving a figure with bbox_inches=\"tight\" fails after inset_axes","articleBody":"### Bug summary\n\nAfter using `inset_axes` in mpl 3.7.2, `savefig` fails if `bbox_inches` is set to \"tight\". This does not fail in 3.7.1.\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\nfrom mpl_toolkits.axes_grid1.inset_locator import inset_axes\r\n\r\n# Test data\r\nx = [i for i in range(10)]\r\ny = [i for i in range(10)]\r\nx_sub = [i for i in range(5)]\r\ny_sub = [i for i in range(5)]\r\n\r\n# Initial figure\r\nfig = plt.figure()\r\nax = fig.add_subplot(111)\r\nax.plot(x, y)\r\n\r\n# Insetted axis and plot\r\ncax = inset_axes(ax, width=\"30%\", height=\"30%\", loc=\"lower right\")\r\ncax.plot(x_sub, y_sub)\r\n\r\n# Saving -- error due to bbox_inches part\r\nfig.savefig(\"test_out.png\", format=\"png\", bbox_inches=\"tight\")\n```\n\n\n### Actual outcome\n\nAttributeError in line 16 (replaced paths to script and lib):\r\n\r\nTraceback (most recent call last):\r\n File \"\u003cpath_to_script\u003e/bug_test.py\", line 16, in \u003cmodule\u003e\r\n fig.savefig(\"test_out.png\", format=\"png\", bbox_inches=\"tight\")\r\n File \"\u003cpath_to_lib\u003e/lib/python3.9/site-packages/matplotlib/figure.py\", line 3378, in savefig\r\n self.canvas.print_figure(fname, **kwargs)\r\n File \"\u003cpath_to_lib\u003e/lib/python3.9/site-packages/matplotlib/backend_bases.py\", line 2353, in print_figure\r\n restore_bbox = _tight_bbox.adjust_bbox(\r\n File \"\u003cpath_to_lib\u003e/lib/python3.9/site-packages/matplotlib/_tight_bbox.py\", line 28, in adjust_bbox\r\n ax.apply_aspect(locator(ax, None))\r\n File \"\u003cpath_to_lib\u003e/lib/python3.9/site-packages/mpl_toolkits/axes_grid1/inset_locator.py\", line 73, in __call__\r\n bbox = self.get_window_extent(renderer)\r\n File \"\u003cpath_to_lib\u003e/lib/python3.9/site-packages/matplotlib/offsetbox.py\", line 399, in get_window_extent\r\n renderer = self.figure._get_renderer()\r\nAttributeError: 'NoneType' object has no attribute '_get_renderer'\r\n\n\n### Expected outcome\n\nA straight line in the main plot with an insetted second line in the lower right corner.\r\n\r\n\r\n\n\n### Additional information\n\nThis worked in mpl 3.7.1 (see expected outcome).\r\n\r\nThis doesn't happen if the `bbox_inches` kwarg is removed.\n\n### Operating system\n\nMacOS\n\n### Matplotlib Version\n\n3.7.2\n\n### Matplotlib Backend\n\nInstalled osx event loop hook. MacOSX\n\n### Python version\n\n3.9.6\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/obriene1","@type":"Person","name":"obriene1"},"datePublished":"2023-08-08T08:11:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/26468/matplotlib/issues/26468"}
| 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:bdb23d69-bf86-875b-e711-7a032d1acb6d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8F18:313BBF:10B12E:16C2A4:6A5259E8 |
| html-safe-nonce | b653a8ff93a0b47d6088f612f010aaa102da676cdee2d8cd385938b5846a3b5f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RjE4OjMxM0JCRjoxMEIxMkU6MTZDMkE0OjZBNTI1OUU4IiwidmlzaXRvcl9pZCI6Ijc1NjAxNjAxMzA5NDk2MDE3NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4bd957373679ef920afe5793fc2ba771eb6bf3312ae06d12220db263a77dd0cb |
| hovercard-subject-tag | issue:1840805463 |
| 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/26468/issue_layout |
| twitter:image | https://opengraph.githubassets.com/969cbaece94ee82422cf68024ce3dc394ed1bd5e9d899286ffd2b5bf4858da65/matplotlib/matplotlib/issues/26468 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/969cbaece94ee82422cf68024ce3dc394ed1bd5e9d899286ffd2b5bf4858da65/matplotlib/matplotlib/issues/26468 |
| og:image:alt | Bug summary After using inset_axes in mpl 3.7.2, savefig fails if bbox_inches is set to "tight". This does not fail in 3.7.1. Code for reproduction import matplotlib.pyplot as plt from mpl_toolkits... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | obriene1 |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width