Title: [Bug]: Axes.cla() resets axis label position of twin axes · Issue #28846 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Axes.cla() resets axis label position of twin axes · Issue #28846 · matplotlib/matplotlib
X Title: [Bug]: Axes.cla() resets axis label position of twin axes · Issue #28846 · matplotlib/matplotlib
Description: Bug summary I'm making many plots in a loop using the same Figure and Axes. The basic setup including a twin Axes is done once and the Axes are cleared at the end of the loop using cla(). Axes.cla() resets the label position of the yaxis...
Open Graph Description: Bug summary I'm making many plots in a loop using the same Figure and Axes. The basic setup including a twin Axes is done once and the Axes are cleared at the end of the loop using cla(). Axes.cla(...
X Description: Bug summary I'm making many plots in a loop using the same Figure and Axes. The basic setup including a twin Axes is done once and the Axes are cleared at the end of the loop using cla(). Axes....
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28846
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Axes.cla() resets axis label position of twin axes","articleBody":"### Bug summary\r\n\r\nI'm making many plots in a loop using the same Figure and Axes. The basic setup including a twin Axes is done once and the Axes are cleared at the end of the loop using `cla()`. \r\n\r\n`Axes.cla()` resets the label position of the `yaxis` of the twin Axes to the default (left), resulting in misplaced ylabels in all but the first loops. \r\n\r\nTicks and tick labels of the left y axis are kept at the correct side, so I would the axis label also expect to be kept at the correct side.\r\n\r\n### Code for reproduction\r\n\r\n```Python\r\nimport matplotlib.pyplot as plt\r\n\r\nfig, ax1 = plt.subplots()\r\nax2 = ax1.twinx()\r\nfor i in range(2):\r\n # do some plotting here\r\n ax2.set(ylabel=f'ylabel of plot # {i}', ylim=(1, i + 2))\r\n fig.savefig(f'{i}.png')\r\n ax1.cla()\r\n ax2.cla()\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n**1.png:**\r\n\r\n\r\n\r\n\r\n### Expected outcome\r\n\r\nThe expected outcome was produced by adding `ax2.yaxis.set_label_position('right')` to the loop: \r\n\r\n\r\n\r\n\r\n### Additional information\r\n\r\n_No response_\r\n\r\n### Operating system\r\n\r\n_No response_\r\n\r\n### Matplotlib Version\r\n\r\n3.9.2\r\n\r\n### Matplotlib Backend\r\n\r\n_No response_\r\n\r\n### Python version\r\n\r\n_No response_\r\n\r\n### Jupyter version\r\n\r\n_No response_\r\n\r\n### Installation\r\n\r\nNone","author":{"url":"https://github.com/StefRe","@type":"Person","name":"StefRe"},"datePublished":"2024-09-19T16:32:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/28846/matplotlib/issues/28846"}
| 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:9487e1bb-cde4-2d65-b141-3c82f853dca2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B9F4:1E565C:32D63A:4461DD:6A52719C |
| html-safe-nonce | 12a5ee12ceb19502f7f802e0a620817345731b851710bab67aecdc6294d1b7c8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUY0OjFFNTY1QzozMkQ2M0E6NDQ2MUREOjZBNTI3MTlDIiwidmlzaXRvcl9pZCI6IjI3Mjc1MjQwOTg0MTQ2Mzc0NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 45c58677ba45c7de95eb39c235d846097f760e5520da31d2be85fa902b2a5f7a |
| hovercard-subject-tag | issue:2536840678 |
| 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/28846/issue_layout |
| twitter:image | https://opengraph.githubassets.com/35471cf625baa902750abbf509d6b64df34fab49549409c470d7dc95cc5b883d/matplotlib/matplotlib/issues/28846 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/35471cf625baa902750abbf509d6b64df34fab49549409c470d7dc95cc5b883d/matplotlib/matplotlib/issues/28846 |
| og:image:alt | Bug summary I'm making many plots in a loop using the same Figure and Axes. The basic setup including a twin Axes is done once and the Axes are cleared at the end of the loop using cla(). Axes.cla(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | StefRe |
| 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