Title: [Bug]: Setting bbox_inches to a Bbox in fig.savefig resizes colorbar · Issue #22625 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Setting bbox_inches to a Bbox in fig.savefig resizes colorbar · Issue #22625 · matplotlib/matplotlib
X Title: [Bug]: Setting bbox_inches to a Bbox in fig.savefig resizes colorbar · Issue #22625 · matplotlib/matplotlib
Description: Bug summary Setting bbox_inches in fig.savefig to a specified Bbox rather than "tight" resizes the colorbar relative to when bbox_inches is not set—the resulting colorbar is a lot larger than it should be. Code for reproduction import nu...
Open Graph Description: Bug summary Setting bbox_inches in fig.savefig to a specified Bbox rather than "tight" resizes the colorbar relative to when bbox_inches is not set—the resulting colorbar is a lot larger than it sh...
X Description: Bug summary Setting bbox_inches in fig.savefig to a specified Bbox rather than "tight" resizes the colorbar relative to when bbox_inches is not set—the resulting colorbar is a lot larger ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22625
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Setting bbox_inches to a Bbox in fig.savefig resizes colorbar","articleBody":"### Bug summary\r\n\r\nSetting bbox_inches in fig.savefig to a specified Bbox rather than \"tight\" resizes the colorbar relative to when bbox_inches is not set—the resulting colorbar is a lot larger than it should be. \r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib as mpl\r\nimport matplotlib.pyplot as plt\r\n\r\nx = np.linspace(0, 2*np.pi, 100)\r\ny = np.linspace(0, 2*np.pi, 100)\r\n\r\nX, Y = np.meshgrid(x,y)\r\n\r\nfig, ax = plt.subplots(figsize=(4,4))\r\n\r\npc = ax.pcolormesh(x, y, np.sin(X)*np.sin(Y))\r\nfig.colorbar(pc, ax=ax, aspect=40)\r\n\r\n# Uncomment the first fig.savefig to get the correct output on the second call\r\n# fig.savefig('nobbox_inches.png')\r\nfig.savefig('bbox_inches.png', bbox_inches=mpl.transforms.Bbox([[0, 0], [4, 4]]))\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\n\r\n\r\n\r\n### Additional information\r\n\r\nCalling fig.savefig without bbox_inches set first and then calling it again with bbox_inches set produces expected outcome.\r\nCalling plt.show() prior to savefig also works.\r\n\r\n### Operating system\r\n\r\nMacOS 12.2.1 (Monterey)\r\n\r\n### Matplotlib Version\r\n\r\n3.5.1\r\n\r\n### Matplotlib Backend\r\n\r\ninline (for interactive), png for plot, also a problem with pdf\r\n\r\n### Python version\r\n\r\n3.9.10\r\n\r\n### Jupyter version\r\n\r\nJupyter lab 3.2.9\r\n\r\n### Installation\r\n\r\nconda","author":{"url":"https://github.com/pittwolfe","@type":"Person","name":"pittwolfe"},"datePublished":"2022-03-08T17:54:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/22625/matplotlib/issues/22625"}
| 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:92dfb08b-1914-7364-c24b-dbb56010c551 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B13A:1880B3:2AF4BC7:3D25284:6A510956 |
| html-safe-nonce | 7572ca3c93a2d7fca07c19042cb8f1cf4ce7c80c128f439b99ec0405805efdb9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTNBOjE4ODBCMzoyQUY0QkM3OjNEMjUyODQ6NkE1MTA5NTYiLCJ2aXNpdG9yX2lkIjoiMzQzODg0NjUxMDI3OTc1NjExOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7e69a0f909a52e770963fe646c9c52a0ac4d833d109d40833d415315bf4a9286 |
| hovercard-subject-tag | issue:1162953113 |
| 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/22625/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4d4e38dafa5c54dc9a41649f84d932a1701d0912eff47bc9629c0594cd0744a0/matplotlib/matplotlib/issues/22625 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4d4e38dafa5c54dc9a41649f84d932a1701d0912eff47bc9629c0594cd0744a0/matplotlib/matplotlib/issues/22625 |
| og:image:alt | Bug summary Setting bbox_inches in fig.savefig to a specified Bbox rather than "tight" resizes the colorbar relative to when bbox_inches is not set—the resulting colorbar is a lot larger than it sh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pittwolfe |
| hostname | github.com |
| expected-hostname | github.com |
| None | b076e100febaa00374cd89239f915d00dd3187f7c68b12bc2b7688181305344d |
| 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 | 2d129404fc45ea64edb1b98567c53e55b395536f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width