Title: axes.get_tightbbox doesn't include legends... · Issue #9130 · matplotlib/matplotlib · GitHub
Open Graph Title: axes.get_tightbbox doesn't include legends... · Issue #9130 · matplotlib/matplotlib
X Title: axes.get_tightbbox doesn't include legends... · Issue #9130 · matplotlib/matplotlib
Description: Bug report The bbox returned by axes.get_tightbbox doesn't include legends that overspill the axis. Bug summary This is an easy fix, but wasn't sure if the behavior was desired: Code for reproduction import matplotlib.pyplot as plt fig, ...
Open Graph Description: Bug report The bbox returned by axes.get_tightbbox doesn't include legends that overspill the axis. Bug summary This is an easy fix, but wasn't sure if the behavior was desired: Code for reproducti...
X Description: Bug report The bbox returned by axes.get_tightbbox doesn't include legends that overspill the axis. Bug summary This is an easy fix, but wasn't sure if the behavior was desired: Code for re...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/9130
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"axes.get_tightbbox doesn't include legends...","articleBody":"\u003c!--To help us understand and resolve your issue, please fill out the form to the best of your ability.--\u003e\r\n\u003c!--You can feel free to delete the sections that do not apply.--\u003e\r\n\r\n### Bug report\r\n\r\nThe `bbox` returned by `axes.get_tightbbox` doesn't include legends that overspill the axis. \r\n\r\n**Bug summary**\r\n\r\nThis is an easy fix, but wasn't sure if the behavior was desired: \r\n\r\n\u003c!--A short 1-2 sentences that succinctly describes the bug--\u003e\r\n\r\n**Code for reproduction**\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\n\r\nfig, ax = plt.subplots()\r\nh = ax.plot(range(10), label='boo')\r\nprint(ax.get_tightbbox(fig.canvas.get_renderer()))\r\nhh = ax.legend(h, 'Boooo', loc='center left', bbox_to_anchor=(0.9, 0.5))\r\nprint(ax.get_tightbbox(fig.canvas.get_renderer()))\r\nprint(hh._legend_box.get_window_extent(renderer))\r\n```\r\n\r\n**Actual outcome**\r\n\r\n```\r\nBbox(x0=61.40277777777777, y0=29.077777777777776, x1=579.5, y1=425.9)\r\nBbox(x0=61.40277777777777, y0=29.077777777777776, x1=579.5, y1=425.9)\r\nBbox(x0=540.288888888889, y0=212.48888888888885, x1=659.413888888889, y1=262.71111111111105)\r\n```\r\n\r\n**Expected outcome**\r\n\r\nThe second `bbox` could have `x1=659.41` to include the legend. \r\n\r\n**solution**\r\n\r\nin `axes/_bases.py` we could change:\r\n\r\n```python\r\n for child in self.get_children():\r\n if isinstance(child, OffsetBox) and child.get_visible():\r\n bb.append(child.get_window_extent(renderer))\r\n elif isinstance(child, Legend) and child.get_visible():\r\n bb.append(child._legend_box.get_window_extent(renderer))\r\n```\r\n\r\n","author":{"url":"https://github.com/jklymak","@type":"Person","name":"jklymak"},"datePublished":"2017-08-30T16:21:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/9130/matplotlib/issues/9130"}
| 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:9d136711-d9d0-a55c-97ae-9b93a99b0194 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AA30:1CAF22:B9019E:F84FB2:6A531BE7 |
| html-safe-nonce | 961bde3884167ef677e47f045f23930b299e1a158677d8dc48c60e7a0dec7440 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTMwOjFDQUYyMjpCOTAxOUU6Rjg0RkIyOjZBNTMxQkU3IiwidmlzaXRvcl9pZCI6IjkxNTc4OTI3MTk1OTA0NDgxMDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | acc1dbd7fcb8f144e71502f5b6e0031605b24d0caf316dd031318df4bb333903 |
| hovercard-subject-tag | issue:254058534 |
| 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/9130/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b0a61f6b3cb59f100595c978bb76f876208bec37a6f4f20b9df180d39d6c7e76/matplotlib/matplotlib/issues/9130 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b0a61f6b3cb59f100595c978bb76f876208bec37a6f4f20b9df180d39d6c7e76/matplotlib/matplotlib/issues/9130 |
| og:image:alt | Bug report The bbox returned by axes.get_tightbbox doesn't include legends that overspill the axis. Bug summary This is an easy fix, but wasn't sure if the behavior was desired: Code for reproducti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jklymak |
| 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