Title: [ENH]: Give control whether twinx() or twiny() overlays the main axis · Issue #31122 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Give control whether twinx() or twiny() overlays the main axis · Issue #31122 · matplotlib/matplotlib
X Title: [ENH]: Give control whether twinx() or twiny() overlays the main axis · Issue #31122 · matplotlib/matplotlib
Description: Problem By default, twinx produces an axis that overlays ax. I routinely find myself wanting to show the twin axis content in the background of the main axis content, and not the other way around. I think this is natural for a user/reade...
Open Graph Description: Problem By default, twinx produces an axis that overlays ax. I routinely find myself wanting to show the twin axis content in the background of the main axis content, and not the other way around. ...
X Description: Problem By default, twinx produces an axis that overlays ax. I routinely find myself wanting to show the twin axis content in the background of the main axis content, and not the other way around. ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/31122
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Give control whether twinx() or twiny() overlays the main axis","articleBody":"### Problem\n\nBy default, twinx produces an axis that overlays ax.\nI routinely find myself wanting to show the twin axis content in the background of the main axis content, and not the other way around.\nI think this is natural for a user/reader that looks at figures, because we tend to read from left to right and hence the data of the left y-axis takes precedence (should render in the foreground).\n\nPreferences aside, the workaround is always the same:\n\n```\n...\nax_t = ax.twinx()\n# make twinx contents appear in the background of main ax\nax.patch.set_visible(False)\nax.set_zorder(ax_t.get_zorder() + 1)\n...\n```\n\nI think ergonomics would increase by an ε if twinx accepted one more `overlay` boolean argument which decides whether the twinx/y is in the \"foreground\" or \"background\" of ax. \n\n### Proposed solution\n\nI would modify the definition of _make_twin_axes (https://github.com/matplotlib/matplotlib/blob/v3.10.8/lib/matplotlib/axes/_base.py#L4595) adding a boolean argument `overlay=true`. \n\nIf false, `self.patch.set_visible(False)` (would this work?) and `twin.set_zorder(self.zorder + 1)`.","author":{"url":"https://github.com/GiusCappelli","@type":"Person","name":"GiusCappelli"},"datePublished":"2026-02-09T14:25:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/31122/matplotlib/issues/31122"}
| 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:f7354652-7aeb-2450-7bf9-b34e5c9d6fd6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E5A4:2BE11D:9A9FFC:D159B4:6A5201C7 |
| html-safe-nonce | 1dcc0dbfe8bff6132cb79692656690ae06409c03f80fd068359734e26a023517 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNUE0OjJCRTExRDo5QTlGRkM6RDE1OUI0OjZBNTIwMUM3IiwidmlzaXRvcl9pZCI6IjMxODYzMjYwMjEyMzU0MDkzNTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a62396f00abe12877545ca72138016ac52cac0bc84df66aee6e1b4077b5091bb |
| hovercard-subject-tag | issue:3916667708 |
| 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/31122/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3e5c8b8722a6328f5838d2727a789d8cfc9486f73c6d57996b060b7b6aa08e30/matplotlib/matplotlib/issues/31122 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3e5c8b8722a6328f5838d2727a789d8cfc9486f73c6d57996b060b7b6aa08e30/matplotlib/matplotlib/issues/31122 |
| og:image:alt | Problem By default, twinx produces an axis that overlays ax. I routinely find myself wanting to show the twin axis content in the background of the main axis content, and not the other way around. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | GiusCappelli |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width