Title: [Bug]: constrained layout clips y-label above y-axis · Issue #27877 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: constrained layout clips y-label above y-axis · Issue #27877 · matplotlib/matplotlib
X Title: [Bug]: constrained layout clips y-label above y-axis · Issue #27877 · matplotlib/matplotlib
Description: Bug summary When placing the y-label above the y-axis/spine, it gets clipped with constrained layout. It works OK with tight layout and on the left in constrained layout. Code for reproduction import matplotlib.pyplot as plt x = range(10...
Open Graph Description: Bug summary When placing the y-label above the y-axis/spine, it gets clipped with constrained layout. It works OK with tight layout and on the left in constrained layout. Code for reproduction impo...
X Description: Bug summary When placing the y-label above the y-axis/spine, it gets clipped with constrained layout. It works OK with tight layout and on the left in constrained layout. Code for reproduction impo...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27877
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: constrained layout clips y-label above y-axis","articleBody":"### Bug summary\r\n\r\nWhen placing the y-label above the y-axis/spine, it gets clipped with constrained layout. It works OK with tight layout and on the left in constrained layout.\r\n\r\n### Code for reproduction\r\n\r\n```Python\r\nimport matplotlib.pyplot as plt\r\nx = range(10)\r\nlab = \"foo bar baz\"\r\n\r\n# with extra space it works, but the second plot with two lines gets\r\n# clipped.\r\nfig0, axes0 = plt.subplots(1, 2, constrained_layout=True)\r\n[ax.plot(x, x) for ax in axes0]\r\n[ax.set_ylabel(\"\\n\".join([lab]*(i+1)),\r\n y=1.0,\r\n rotation=\"horizontal\",\r\n horizontalalignment=\"left\",\r\n multialignment=\"left\",)\r\n for i, ax in enumerate(axes0)]\r\n\r\n# single plot with one line also gets clipped\r\nfig1, ax1 = plt.subplots(constrained_layout=True)\r\nax1.plot(x, x)\r\nax1.set_ylabel(lab,\r\n y=1.0,\r\n rotation=\"horizontal\",\r\n horizontalalignment=\"left\",\r\n multialignment=\"left\",)\r\n\r\n# For reference it works fine when placing the ylab on the 'side'\r\n# as a conventional matplotlib plot\r\nfig2, ax2 = plt.subplots(constrained_layout=True)\r\nax2.plot(x, x)\r\nax2.set_ylabel(f\"{lab}\\n{lab}\",\r\n rotation=\"horizontal\",\r\n horizontalalignment=\"right\",\r\n multialignment=\"right\",)\r\n\r\nfor i, fig in enumerate((fig0, fig1, fig2)):\r\n fig.savefig(f\"fig{i}.png\")\r\n```\r\n\r\n### Actual outcome\r\n\r\nThe y-label gets clipped. The second plot should have a two line long y label. \r\n\r\n\r\nIt also happens with a y-label that is just one line:\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nI would expect the y label to be included, even when putting it above the axis. Example with tight layout (`fig1.tight_layout()`)\r\n\r\n\r\n\r\n\r\n### Additional information\r\n\r\nI *think* this is a bug(?). \r\nI have tried various vertical alignments, and it doesn't make much of a difference. I also tried to follow the legend `set_in_layout`-example in the [constrained layout guide](https://matplotlib.org/stable/users/explain/axes/constrainedlayout_guide.html#legends) without much luck.\r\n\r\nA temporary fix is to set the title to `' '` or increasing the constrained layout padding, I guess. \r\n\r\nNote that constrained layout works as expected with long y-labels on the left:\r\n\r\n\r\n\r\n\r\n### Operating system\r\n\r\nWindows\r\n\r\n### Matplotlib Version\r\n\r\n3.8.0\r\n\r\n### Matplotlib Backend\r\n\r\nmodule://matplotlib_inline.backend_inline, but present in saved figures (`savefig`) \r\n\r\n### Python version\r\n\r\n3.12.1\r\n\r\n### Jupyter version\r\n\r\nJupyter console 6.6.3\r\n\r\n### Installation\r\n\r\nconda","author":{"url":"https://github.com/pank","@type":"Person","name":"pank"},"datePublished":"2024-03-07T13:36:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/27877/matplotlib/issues/27877"}
| 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:7c193503-77cc-1a48-ff8a-52ea58fda9dc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B09C:AE90C:3E7A97:5503E6:6A559920 |
| html-safe-nonce | ece5f2c06de83a94c1ca1615d9787c7bfdb59aaa3e752287ae90b15cc6462208 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDlDOkFFOTBDOjNFN0E5Nzo1NTAzRTY6NkE1NTk5MjAiLCJ2aXNpdG9yX2lkIjoiODExOTY2NzQ3MDUxNDg4Njk0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1951b7ee1decb3d17d59ea79184b33c4a98c91ac7c8f6f1910f613a5af919c3e |
| hovercard-subject-tag | issue:2173884921 |
| 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/27877/issue_layout |
| twitter:image | https://opengraph.githubassets.com/511d9616ddd9339081e9a744fd0187f86d7eb714daad4c4604731f049fa516bf/matplotlib/matplotlib/issues/27877 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/511d9616ddd9339081e9a744fd0187f86d7eb714daad4c4604731f049fa516bf/matplotlib/matplotlib/issues/27877 |
| og:image:alt | Bug summary When placing the y-label above the y-axis/spine, it gets clipped with constrained layout. It works OK with tight layout and on the left in constrained layout. Code for reproduction impo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pank |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | aa21baa44893467b0b640d0300538f84ca8c475b |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width