Title: xlim is not auto scaled when using twinx · Issue #16723 · matplotlib/matplotlib · GitHub
Open Graph Title: xlim is not auto scaled when using twinx · Issue #16723 · matplotlib/matplotlib
X Title: xlim is not auto scaled when using twinx · Issue #16723 · matplotlib/matplotlib
Description: I am reporting as possible bug. When plotting a secondary y axis on the right, the xlim is not being properly auto scaled. As possible work around was proposed here, https://stackoverflow.com/a/27344398/4988010, however, it seems this wa...
Open Graph Description: I am reporting as possible bug. When plotting a secondary y axis on the right, the xlim is not being properly auto scaled. As possible work around was proposed here, https://stackoverflow.com/a/273...
X Description: I am reporting as possible bug. When plotting a secondary y axis on the right, the xlim is not being properly auto scaled. As possible work around was proposed here, https://stackoverflow.com/a/273...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/16723
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"xlim is not auto scaled when using twinx","articleBody":"I am reporting as possible bug.\r\n\r\nWhen plotting a secondary y axis on the right, the xlim is not being properly auto scaled. As possible work around was proposed here, https://stackoverflow.com/a/27344398/4988010, however, it seems this was fixed here, https://github.com/matplotlib/matplotlib/commit/26ed35b78cd7542f6841835925be53419661e36e. However, I am not seeing the issue being resolved on matplotlib v3.2.0. \r\n\r\n```python\r\n%matplotlib widget\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nfig, ax = plt.subplots()\r\ndecay = lambda C, K, x: C *(1-np.exp(-1*K*x))\r\nx = np.linspace(0,10,10)\r\n\r\n# Create a secondary y axis on the right\r\ntwin_ax = ax.twinx()\r\n\r\nfor n in range(5):\r\n C = n**2 + 5\r\n K = 0.75\r\n # Plot the exponential decay on left y axis \r\n ax.plot(x,decay(C,K,x), marker='o', linestyle='--', label=C)\r\n # Plot the limit of decay on right y axis \r\n twin_ax.axhline(y=C, color='gray') \r\n \r\nax.legend()\r\nax.set_xlabel('X')\r\nax.set_ylabel('Measured values')\r\ntwin_ax.set_ylabel('Theoritical limit')\r\n\r\n# Align the both left and right y axis \r\ntwin_ax.set_ylim(ax.get_ylim())\r\n\r\n##################\r\n# Issues or bugs\r\n# Need to fix the X limits or else \r\n# the graph doens't display properly\r\n##################\r\n\r\nprint('xlim before fix: {}'.format(ax.get_xlim()))\r\nax.relim()\r\nprint('xlim after relim(): {}'.format(ax.get_xlim()))\r\n# A hack to fix the issue # https://stackoverflow.com/a/27344398/4988010\r\ntwin_ax.plot(0, 0, visible=False)\r\nprint('xlim after fixing: {}'.format(ax.get_xlim()))\r\n\r\nplt.show()\r\n```\r\n\r\n\r\n","author":{"url":"https://github.com/01baftb","@type":"Person","name":"01baftb"},"datePublished":"2020-03-10T22:27:24.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/16723/matplotlib/issues/16723"}
| 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:9f6303df-7fe5-b212-886d-504fb52540f0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83B2:19B879:1259965:18F100A:6A5454E0 |
| html-safe-nonce | ed79bf6b5d32aaad6189420bd5939e4bdd3670f1a8692980b85234200c5cad96 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0IyOjE5Qjg3OToxMjU5OTY1OjE4RjEwMEE6NkE1NDU0RTAiLCJ2aXNpdG9yX2lkIjoiNTMxOTk5NTQwNTE0NDE4NDAzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7643536b4e69a8ce34be8aa0af0792e16161a725ff9af8bc3c63e012c23a6a73 |
| hovercard-subject-tag | issue:578897819 |
| 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/16723/issue_layout |
| twitter:image | https://opengraph.githubassets.com/22092ed4b3b34f8b8dd2512723d656a8b56fb9358b7bac1aa14a5233d87c09e5/matplotlib/matplotlib/issues/16723 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/22092ed4b3b34f8b8dd2512723d656a8b56fb9358b7bac1aa14a5233d87c09e5/matplotlib/matplotlib/issues/16723 |
| og:image:alt | I am reporting as possible bug. When plotting a secondary y axis on the right, the xlim is not being properly auto scaled. As possible work around was proposed here, https://stackoverflow.com/a/273... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 01baftb |
| 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 | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width