-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Reuse InsetLocator to make twinned axes follow their parents. #18456
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
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.
Looks reasonable. Can you add your sample code as a test?
I think this idea is great, but can we rename |
I renamed the thing to TransformedBoundsLocator, given that it locates an axes using tranformed bbox bounds. |
The tests help codify expected behaviour. If someone rewrites all of this from scratch it would be nice if this behaviour would be explicitly tested. |
My point is that the behavior is already codified in all the tests for twinned axes, and that it would really require conscious malfeasance :-) to go back to the old behavior (you need to put back the manual position tracking). |
? you have a case that was broken for a previous implementation. This implementation presumably fixes that case, so having a test would be preferable. |
It was broken because of some rather roundabout way of trying to keep track of twinning (by equating twinning with sharing), which I am arguing is very unlikely to be reintroduced. |
@anntzer You've been able to change library behavior without a test failing. That's bad. Therefore, we should have a test. Given that the test should be all of 6 lines, that doesn't seem like a huge maintenance burden for the project to assume. |
sure... |
@@ -6513,3 +6513,12 @@ def test_multiplot_autoscale(): | |||
ax2.axhspan(-5, 5) | |||
xlim = ax1.get_xlim() | |||
assert np.allclose(xlim, [0.5, 4.5]) | |||
|
|||
|
|||
def test_sharing_does_not_link_positions(): |
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.
does not or does? I'm confused, as the final assert
checks for equality.
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.
it's checking that the position of the shared axes did not change (i.e. that it did not get linked to the position of the sharee).
From a positioning PoV, a twinned axes is just like an inset axes whose position exactly matches the parent's position. Doing so removes the need for the heuristic in `Figure.subplots_adjust`/`GridSpec.update` where a non-gridspec-managed Axes would track the position of any Axes with which it shared either xaxis or yaxis, which was a proxy for twinning (per 721b949). This would cause incorrect behavior in rare cases such as ```python from pylab import * ax = subplot(221) axes([.6, .6, .3, .3], sharex=ax) subplots_adjust(left=0) ``` where the `subplots_adjust` call would make the second axes go on top of the first.
From a positioning PoV, a twinned axes is just like an inset axes whose
position exactly matches the parent's position. Doing so removes the
need for the heuristic in
Figure.subplots_adjust
/GridSpec.update
where a non-gridspec-managed Axes would track the position of any Axes
with which it shared either xaxis or yaxis, which was a proxy for
twinning (per 721b949). This would cause incorrect behavior in rare
cases such as
where the
subplots_adjust
call would make the second axes go on top ofthe first.
PR Summary
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
andpydocstyle<4
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).