Title: [Bug]: AnnotationBbox does not return correct window_extent before first draw · Issue #24453 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: AnnotationBbox does not return correct window_extent before first draw · Issue #24453 · matplotlib/matplotlib
X Title: [Bug]: AnnotationBbox does not return correct window_extent before first draw · Issue #24453 · matplotlib/matplotlib
Description: Bug summary I’m trying to use a constrained layout in a visualization that contains an artist that is an instance of AnnotationBbox, and matplotlib raises a warning saying constrained layout is not applied. The visual effect is not evide...
Open Graph Description: Bug summary I’m trying to use a constrained layout in a visualization that contains an artist that is an instance of AnnotationBbox, and matplotlib raises a warning saying constrained layout is not...
X Description: Bug summary I’m trying to use a constrained layout in a visualization that contains an artist that is an instance of AnnotationBbox, and matplotlib raises a warning saying constrained layout is not...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/24453
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: AnnotationBbox does not return correct window_extent before first draw","articleBody":"### Bug summary\n\nI’m trying to use a constrained layout in a visualization that contains an artist that is an instance of AnnotationBbox, and matplotlib raises a warning saying constrained layout is not applied. The visual effect is not evident in this simple example, but it becomes very clear once we have multiple panels.\n\n### Code for reproduction\n\n```python\nimport matplotlib\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.offsetbox import AnnotationBbox, TextArea\r\n\r\nfig, ax = plt.subplots(layout=\"constrained\")\r\n\r\nab = AnnotationBbox(\r\n TextArea(\"Some text\", textprops={\"size\": 42}),\r\n (0.5, 0.5),\r\n xycoords=\"axes fraction\",\r\n box_alignment=(0.5, 0.5),\r\n pad=0\r\n)\r\n\r\nax.add_artist(ab)\r\nfig.set_facecolor(\"w\")\r\nfig.savefig(\"annotation_box.png\", dpi=300)\n```\n\n\n### Actual outcome\n\nUserWarning: constrained_layout not applied because axes sizes collapsed to zero. Try making figure larger or axes decorations smaller.\r\n\n\n### Expected outcome\n\nNo warning should appear\n\n### Additional information\n\nThe following works without any warning\r\n\r\n```python\r\nfig, ax = plt.subplots(layout=\"constrained\")\r\nax.text(0.5, 0.5, \"Some text\", size=42, ha=\"center\")\r\nfig.set_facecolor(\"w\")\r\nfig.savefig(\"ax_text.png\", dpi=300)\r\n```\r\n\r\n\r\nThe problem with the constrained layout is more evident if I have two or more panels.\r\nOne way of fixing it (i.e. getting rid of the warning and bad functionality) is to do ab.set_in_layout(False) before doing ax.add_artist(ab).\r\n\r\nThis was first posted on Discourse https://discourse.matplotlib.org/t/constrained-layout-does-not-work-well-with-annotationbbox/23301\n\n### Operating system\n\nUbuntu 22\n\n### Matplotlib Version\n\n3.6.2\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n_No response_\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/tomicapretto","@type":"Person","name":"tomicapretto"},"datePublished":"2022-11-14T18:39:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":14},"url":"https://github.com/24453/matplotlib/issues/24453"}
| 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:dee0d602-d3e6-6043-f91f-9a8728e3731b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBC4:51AC4:B29B3B:F25BCF:6A51628B |
| html-safe-nonce | 31d57c607531d82e137634f0015f2ec975198518c2e650b1c5ec979c1920d7ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkM0OjUxQUM0OkIyOUIzQjpGMjVCQ0Y6NkE1MTYyOEIiLCJ2aXNpdG9yX2lkIjoiNDU2Nzk2NTcxNDE1NDA4NzA1MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 41a12d44577d337bc8355a85d1cf8eaf1674c53e11a7f8601678a33f657d468b |
| hovercard-subject-tag | issue:1448555312 |
| 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/24453/issue_layout |
| twitter:image | https://opengraph.githubassets.com/392176b0f6e5ff7e0dd31d207677545e495f6fa84b1893b471d60fdcbf258937/matplotlib/matplotlib/issues/24453 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/392176b0f6e5ff7e0dd31d207677545e495f6fa84b1893b471d60fdcbf258937/matplotlib/matplotlib/issues/24453 |
| og:image:alt | Bug summary I’m trying to use a constrained layout in a visualization that contains an artist that is an instance of AnnotationBbox, and matplotlib raises a warning saying constrained layout is not... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tomicapretto |
| 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 | 2eeb434949a926fad21064b4d395a54759f7a0b2 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width