Title: [Bug]: Colorbar is displaced when saving as .pdf with bbox_inches='tight' and by using inset_axes · Issue #27143 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Colorbar is displaced when saving as .pdf with bbox_inches='tight' and by using inset_axes · Issue #27143 · matplotlib/matplotlib
X Title: [Bug]: Colorbar is displaced when saving as .pdf with bbox_inches='tight' and by using inset_axes · Issue #27143 · matplotlib/matplotlib
Description: Bug summary I use imshow() with colorbar and inset_axes to zoom into the image. After saving the pdf with savefigure() and bbox_inches='tight' the colorbar is shifted. Very similar to bug #25176, which has already been fixed. The problem...
Open Graph Description: Bug summary I use imshow() with colorbar and inset_axes to zoom into the image. After saving the pdf with savefigure() and bbox_inches='tight' the colorbar is shifted. Very similar to bug #25176, w...
X Description: Bug summary I use imshow() with colorbar and inset_axes to zoom into the image. After saving the pdf with savefigure() and bbox_inches='tight' the colorbar is shifted. Very similar to bug #...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27143
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Colorbar is displaced when saving as .pdf with bbox_inches='tight' and by using inset_axes","articleBody":"### Bug summary\r\n\r\nI use `imshow()` with `colorbar` and `inset_axes` to zoom into the image. After saving the pdf with `savefigure()` and `bbox_inches='tight'` the colorbar is shifted.\r\nVery similar to bug #25176, which has already been fixed. \r\n\r\nThe problem only occurs when using the `bbox_inches='tight'` option in combination with `inset_axes`.\r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nimport matplotlib.cbook as cbook\r\nimport matplotlib.cm as cm\r\nfrom matplotlib.patches import PathPatch\r\nfrom matplotlib.path import Path\r\nnp.random.seed(19680801)\r\ndelta = 0.025\r\nx = y = np.arange(-3.0, 3.0, delta)\r\nX, Y = np.meshgrid(x, y)\r\nZ1 = np.exp(-X**2 - Y**2)\r\nZ2 = np.exp(-(X - 1)**2 - (Y - 1)**2)\r\nZ = (Z1 - Z2) * 2\r\n\r\nfig, ax = plt.subplots()\r\nim = ax.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn,\r\n origin='lower', extent=[-3, 3, -3, 3],\r\n vmax=abs(Z).max(), vmin=-abs(Z).max())\r\ncb = plt.colorbar(mappable=im)\r\nplt.show()\r\naxins = inset_axes(ax, width='20%', height='20%', loc='upper right')\r\nZ2 = axins.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn,\r\n origin='lower', extent=[-3, 3, -3, 3],\r\n vmax=abs(Z).max(), vmin=-abs(Z).max())\r\nx1, x2, y1, y2 = -1,0,0,1\r\naxins.set_xlim(x1, x2)\r\naxins.set_ylim(y1, y2)\r\nrectpatch, connects = ax.indicate_inset_zoom(axins, edgecolor = 'k',alpha=1, lw = 1)\r\nconnects[0].set_visible(False)\r\nconnects[1].set_visible(True)\r\nconnects[2].set_visible(True)\r\nconnects[3].set_visible(False)\r\n\r\nfig.savefig(\"temp.pdf\",\r\n bbox_inches='tight',\r\n transparent=True,\r\n format=\"pdf\")\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n[temp.pdf](https://github.com/matplotlib/matplotlib/files/13042716/temp.pdf)\r\n\r\n\r\n### Expected outcome\r\n\r\nSomthing like this:\r\n\r\n[temp.pdf](https://github.com/matplotlib/matplotlib/files/13042712/temp.pdf)\r\n\r\nbut with tight layout\r\n\r\n### Additional information\r\n\r\nPython version : \r\nMatplotlib version: \r\n\r\n### Operating system\r\n\r\nOS: Linux Fedora 37 (Workstation Edition)\r\n\r\n### Matplotlib Version\r\n\r\n3.8.0\r\n\r\n### Matplotlib Backend\r\n\r\nmodule://ipympl.backend_nbagg\r\n\r\n### Python version\r\n\r\n3.11.5\r\n\r\n### Jupyter version\r\n\r\nmodule://ipympl.backend_nbagg\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/Hexanders","@type":"Person","name":"Hexanders"},"datePublished":"2023-10-19T12:48:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/27143/matplotlib/issues/27143"}
| 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:5306c8b7-9798-ac04-29e8-2bbb5031f29a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D784:1FF3C2:1B21FC:24CF41:6A525579 |
| html-safe-nonce | 5e7ce2cfbe2f0a66627d8c2436f105d2e5441bdfbcf28d5cd530fdd68506e8b9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzg0OjFGRjNDMjoxQjIxRkM6MjRDRjQxOjZBNTI1NTc5IiwidmlzaXRvcl9pZCI6IjM5NzU1Mjk0MjI5NzEzNjA2MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 40385789cb710964f94f549df8ed483e22b9d5b15a083a247ac94e5d1e8b95e3 |
| hovercard-subject-tag | issue:1952180071 |
| 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/27143/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aa97a7b62a94726864015b7edee31ecdedc9825b4c1bbbf384918878effd0a45/matplotlib/matplotlib/issues/27143 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aa97a7b62a94726864015b7edee31ecdedc9825b4c1bbbf384918878effd0a45/matplotlib/matplotlib/issues/27143 |
| og:image:alt | Bug summary I use imshow() with colorbar and inset_axes to zoom into the image. After saving the pdf with savefigure() and bbox_inches='tight' the colorbar is shifted. Very similar to bug #25176, w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Hexanders |
| 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