-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fixed xlim issue when clearing shared axes #28101
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
To make sure I understand what is going on here fig = plt.figure()
subfigs = fig.subfigures(1, 2)
(ax1, ax2) = subfigs[0].subplots(2, sharex=True)
ax2.plot(range(500))
ax1.cla()
(ax1, ax2) = subfigs[1].subplots(2, sharex=True)
ax1.plot(range(500))
ax2.cla() and by setting the bi-directional sharing makes them behave the same (presumably there is a "do I have a share friend? if so don't reset my limits" check someplace else?) This definitely needs a test. I think something like my example in a compare_images test (do it once to the test image with the |
TL;DR: I believe we need to define the intended behavior of On a general note: Do we have a precise idea what Note for example that with the new version
maintains the 0, 500 xlim on both axes due to the cross-wise sharing blocking a reset of the limits. Whereas the same code without Logically, the situation is ill-defined: We can't have both: clear (reset) limits of a single Axes AND still share with another Axes that should keep its limits. One could as well argue that
would result in the same internal state as
but we currently don't do this, and it might be hard to implement. |
Regarding the semantics of clear(): I think the semantics (in the case here) should be as follows:
(*) This "lazy dataLim" computation is also needed to make #15595 (add an in_autoscale property to artists) work in the case of the property being updated. (See also #7413 (comment).) |
@anntzer The described behavior sounds reasonable. Just to be sure I understand correctly: Changing to "lazy dataLim" is necessary and may be a substantial effort.
I'm not so sure. While current behavior, this is not really desireable/intuitive. Not continuing to adapt the limits to show all data unless explicit limits are set is even dangerous: One may accitentally overlook new data. - I fixed limits are desired, users should explicitly opt-in. I would be willing to consider a breaking change here after a deprecation period (whether that deprecation can be supported by a runtime warning with reasonable effort would need to be inverstigated but is not necessarily a blocker). - Long-term, not having to cache inital limits would also make the code simpler. |
|
I have serious doubts that approach in this PR (i.e. mutual sharing) is the right solution. It has possibly unintended implications (#28101 (comment)). I suspect that the only clean way forward is to go for lazy datalims as discussed above. |
In my opinion calling a On the other hand it could also be reasonable to break the axes sharing while calling the The point here is to decide which of |
PR summary
Making sure that when two subplots are sharing an axes, clearing the leader one doesn't also reset the xlim and ylim to [0,1]
Befor PR:
After PR:

PR checklist