Title: [ENH]: Allow ignoring x-extent (but not y-extent) of xticklabels when computing axes extents (e.g. for geometry manager) · Issue #30263 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Allow ignoring x-extent (but not y-extent) of xticklabels when computing axes extents (e.g. for geometry manager) · Issue #30263 · matplotlib/matplotlib
X Title: [ENH]: Allow ignoring x-extent (but not y-extent) of xticklabels when computing axes extents (e.g. for geometry manager) · Issue #30263 · matplotlib/matplotlib
Description: Problem Currently, if an xtick is at the very edge of an x-axis, and thus the xticklabel "overhangs" further, then it will be taken into account for constrained_layout (CL) purposes. Unfortunately, this means that the axes size, after CL...
Open Graph Description: Problem Currently, if an xtick is at the very edge of an x-axis, and thus the xticklabel "overhangs" further, then it will be taken into account for constrained_layout (CL) purposes. Unfortunately,...
X Description: Problem Currently, if an xtick is at the very edge of an x-axis, and thus the xticklabel "overhangs" further, then it will be taken into account for constrained_layout (CL) purposes. Unfo...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30263
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Allow ignoring x-extent (but not y-extent) of xticklabels when computing axes extents (e.g. for geometry manager)","articleBody":"### Problem\n\nCurrently, if an xtick is at the very edge of an x-axis, and thus the xticklabel \"overhangs\" further, then it will be taken into account for constrained_layout (CL) purposes. Unfortunately, this means that the axes size, after CL runs, will depend on whether there is such an \"edge\" xtick. In some cases, it may be preferable to ignore the x-extent of that ticklabel, even if it ends up \"going over\" the edge of the figure, to maintain the same axes size. (An example use case is when exporting multiple figures, all with similar axes only differing by whether there's an overhanging xticklabel, to SVG, as with this format one can just readjust the viewport of the SVG to unclip the ticklabel.)\n\nConcretely, consider the following example:\n```python\nfrom pylab import *\n\nax = plt.figure(layout=\"constrained\", figsize=(3, 3)).add_subplot(xlim=(-.1, 1.1))\nax = plt.figure(layout=\"constrained\", figsize=(3, 3)).add_subplot(xlim=(0, 1))\n\nshow()\n```\nRight now the axes have slightly different physical sizes, because the second one is reduced to give room to the edge tick at x=1.\n\nI would like to be able to do something like (\\*)\n```python\nfrom pylab import *\n\nax = plt.figure(layout=\"constrained\", figsize=(3, 3)).add_subplot(xlim=(-.1, 1.1))\nax = plt.figure(layout=\"constrained\", figsize=(3, 3)).add_subplot(xlim=(0, 1))\nax.figure.draw_without_rendering()\nax.xaxis.majorTicks[-1].label1.set_in_layout(False)\n\nshow()\n```\nto force the last xtick to be ignored for CL purposes.\n\nMaking this work is actually relatively easy; I believe the patch is simply\n```patch\ndiff --git i/lib/matplotlib/axis.py w/lib/matplotlib/axis.py\nindex fafdf92017..a9b31ebb4e 100644\n--- i/lib/matplotlib/axis.py\n+++ w/lib/matplotlib/axis.py\n@@ -1335,9 +1335,11 @@ class Axis(martist.Artist):\n if renderer is None:\n renderer = self.get_figure(root=True)._get_renderer()\n return ([tick.label1.get_window_extent(renderer)\n- for tick in ticks if tick.label1.get_visible()],\n+ for tick in ticks\n+ if tick.label1.get_visible() and tick.label1.get_in_layout()],\n [tick.label2.get_window_extent(renderer)\n- for tick in ticks if tick.label2.get_visible()])\n+ for tick in ticks\n+ if tick.label2.get_visible() and tick.label2.get_in_layout()])\n \n def get_tightbbox(self, renderer=None, *, for_layout_only=False):\n \"\"\"\n```\nbut a few questions remain\n- The end-user experience is not great if one really needs to do (\\*); can we design a better API?\n- Ideally, I only want to ignore the x-extent of the xticklabels, not their y-extent (although in practice I'm saved by the fact that *other* xticks contribute the necessary info for the y-extent). Should we introduce set_in_layout_x() and set_in_layout_y()?\n\nOf course, the same applies for the y-extent of yticklabels.\n\n### Proposed solution\n\nSee above.","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2025-07-04T21:58:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/30263/matplotlib/issues/30263"}
| 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:e5263157-790e-dabf-3e21-cb144f46541e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A28:2E411E:D52D5:11BCB3:6A52E045 |
| html-safe-nonce | b177f9a67ff39f21e0a0ef9a3b545b21c8c102dfb48338bbc14b255fe8b9a2f9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QTI4OjJFNDExRTpENTJENToxMUJDQjM6NkE1MkUwNDUiLCJ2aXNpdG9yX2lkIjoiMjY2NTcyNTMwNDM0NjE3MzUwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c7b5ab0098cafd111979b49ef0ba0a50fe53a006f898afff1c6ea4de70b4797b |
| hovercard-subject-tag | issue:3203764553 |
| 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/30263/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7c3dccaa02b535c1a43e585ff5ea07dd097efc382958f9e97be335935f766f0b/matplotlib/matplotlib/issues/30263 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7c3dccaa02b535c1a43e585ff5ea07dd097efc382958f9e97be335935f766f0b/matplotlib/matplotlib/issues/30263 |
| og:image:alt | Problem Currently, if an xtick is at the very edge of an x-axis, and thus the xticklabel "overhangs" further, then it will be taken into account for constrained_layout (CL) purposes. Unfortunately,... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| 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