Title: [Bug]: inset colorbar colours and frame misaligned · Issue #29383 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: inset colorbar colours and frame misaligned · Issue #29383 · matplotlib/matplotlib
X Title: [Bug]: inset colorbar colours and frame misaligned · Issue #29383 · matplotlib/matplotlib
Description: Bug summary Following #29340, when a colorbar is added in an inset axes there is still a small mismatch between the frame and the colours of the colorbar, as shown in the test image added at #29340. That test uses the toolkits inset_axes...
Open Graph Description: Bug summary Following #29340, when a colorbar is added in an inset axes there is still a small mismatch between the frame and the colours of the colorbar, as shown in the test image added at #29340...
X Description: Bug summary Following #29340, when a colorbar is added in an inset axes there is still a small mismatch between the frame and the colours of the colorbar, as shown in the test image added at #29340...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29383
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: inset colorbar colours and frame misaligned","articleBody":"### Bug summary\r\n\r\nFollowing #29340, when a colorbar is added in an inset axes there is still a small mismatch between the frame and the colours of the colorbar, as shown in the [test image added at #29340](https://github.com/rcomer/matplotlib/blob/0908973e108e945533b02f6ddf1f1227fbbf9b66/lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_inset_rasterized.pdf). That test uses the toolkits `inset_axes` but the problem also appears when using `Axes.inset_axes`.\r\n\r\n### Code for reproduction\r\n\r\nFrom https://github.com/matplotlib/matplotlib/issues/27763#issuecomment-1936312401:\r\n\r\n```Python\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig, axes = plt.subplots(1, 1, layout='constrained')\r\n\r\nx = np.random.randint(100, size=(30, 200))\r\nc = axes.imshow(x, origin='lower', cmap='Reds', aspect=1)\r\naxins1 = axes.inset_axes([0.05, 0.8, 0.2, 0.09])\r\n\r\nfig.colorbar(c, cax=axins1, orientation=\"horizontal\")\r\n\r\nfig.savefig('test_single.pdf', bbox_inches='tight')\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\nColorbar frame should be lined up with its colours.\r\n\r\n### Additional information\r\n\r\nTo reproduce the bug we need\r\n* Rasterized artist in `inset_axes`\r\n* Saving with `bbox_inches='tight'`\r\n* Saving as pdf, so perhaps linked to the mixed-mode renderer calling `adjust_bbox` multiple times via `process_figure_for_rasterizing`.\r\n\r\nIncreasing the figure dpi to 300 makes the problem disappear. Also, when I originally wrote the test at #29340 I forgot to set the style. The problem did not show up with classic mode.\r\n\r\nI have reproduced with v3.2, so probably this never worked.\r\n\r\n### Operating system\r\n\r\nUbuntu\r\n\r\n### Matplotlib Version\r\n\r\n`main`\r\n\r\n### Matplotlib Backend\r\n\r\nQtAgg\r\n\r\n### Python version\r\n\r\n3.12.5\r\n\r\n### Jupyter version\r\n\r\nn/a\r\n\r\n### Installation\r\n\r\ngit checkout","author":{"url":"https://github.com/rcomer","@type":"Person","name":"rcomer"},"datePublished":"2024-12-28T12:36:30.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/29383/matplotlib/issues/29383"}
| 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:9fa2967b-d574-a75f-efc8-dd268df8fcb0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A6EA:25211B:495763:618326:6A52F583 |
| html-safe-nonce | 524fd1a9b61e65bf9334ade5f78168b098e3500d56654aac3331df1263931c1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNkVBOjI1MjExQjo0OTU3NjM6NjE4MzI2OjZBNTJGNTgzIiwidmlzaXRvcl9pZCI6IjM3NjY2NzQwNTM5NDkyMjQzMjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2695fb70af4b514b2151862a05355eea8ffcd4ce4ad1cb82321f23b9ea1240af |
| hovercard-subject-tag | issue:2761704165 |
| 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/29383/issue_layout |
| twitter:image | https://opengraph.githubassets.com/24c19aa563df334ff6a7983e463d567ff1e3b6ff89c8ad0c984660a6299bdf7c/matplotlib/matplotlib/issues/29383 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/24c19aa563df334ff6a7983e463d567ff1e3b6ff89c8ad0c984660a6299bdf7c/matplotlib/matplotlib/issues/29383 |
| og:image:alt | Bug summary Following #29340, when a colorbar is added in an inset axes there is still a small mismatch between the frame and the colours of the colorbar, as shown in the test image added at #29340... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rcomer |
| 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