Skip to content

Fix issue with shared x-axis resetting when calling cla() on shared axes #28697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

ydotwang
Copy link

@ydotwang ydotwang commented Aug 9, 2024

PR summary

Fix bidirectional axis sharing in sharex, sharey, and __clear methods

Description:
This pull request addresses issues related to the handling of shared axes (sharex and sharey) in Matplotlib, particularly in scenarios involving clearing of axes.

Summary of Changes:
Bidirectional Sharing:
The sharex and sharey methods have been updated to ensure bidirectional sharing of axes. Previously, when axis A shared its x-axis with axis B, changes to B would not affect A. This has been corrected by ensuring that B also shares its x-axis back with A.

Impact:
These changes resolve the issue where shared axes would not behave symmetrically, leading to unexpected behavior when clearing axes or working with inverted axes. The updates ensure consistent and predictable behavior in shared axes scenarios.

Before PR:
image

After PR:
image

Testing:
Existing tests related to shared axes should be reviewed to ensure they cover these scenarios. New tests can be added to specifically verify bidirectional sharing and correct inversion handling during clearing.
This pull request ensures that Matplotlib handles shared axes in a robust manner, improving the overall user experience when working with subplots and synchronized axes.

PR checklist

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@ydotwang ydotwang reopened this Aug 9, 2024
@ydotwang ydotwang changed the title Fix issue with shared x-axis resetting when calling cla() on shared axes Fix issue with shared x-axis resetting when calling cla() on shared axes Issure with #27825 Aug 10, 2024
@ydotwang ydotwang changed the title Fix issue with shared x-axis resetting when calling cla() on shared axes Issure with #27825 Fix issue with shared x-axis resetting when calling cla() on shared axes Aug 10, 2024
@rcomer
Copy link
Member

rcomer commented Sep 7, 2024

Thanks for your contribution @ydotwang! Please could you add a test to ensure this behaviour does not break again in future?

@timhoffm
Copy link
Member

timhoffm commented Sep 9, 2024

This is a dupliate. The approach was suggested in the original issue and the poster already made a PR (#28101). Discussion should continue in that PR.

@ydotwang
Copy link
Author

Thanks for your contribution @ydotwang! Please could you add a test to ensure this behaviour does not break again in future?

Hi, I see. I would like to write tests for this! Could you give me some advice?

@timhoffm
Copy link
Member

@ydotwang thanks for the interest. It's currently not possible to write a test. The solution of mutually sharing Axes would solve the concrete issue, however it would introduce other issues. The proper way forward is laid out in #28101 (comment), but it's a non-trivial rearchitecturing. Tests will need to be written in the process of that migration.

@ydotwang
Copy link
Author

@ydotwang thanks for the interest. It's currently not possible to write a test. The solution of mutually sharing Axes would solve the concrete issue, however it would introduce other issues. The proper way forward is laid out in #28101 (comment), but it's a non-trivial rearchitecturing. Tests will need to be written in the process of that migration.

Thank you for your answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[Bug]: Axes.cla() with sharex may wrongly reset the axes limit.
4 participants