-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Synchronize view limits of shared axes after setting ticks #18529
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.
I'm a little leery of this behaviour.... You can imagine a user wanting exactly the opposite: they have some shared axes, but they want one of the axes to have different explicit ticks, but keep the same x/y limits. I didn't read the original issue - is this really a change we want?
else: | ||
shared = [self] | ||
for axis in shared: | ||
if len(ticks) > 1: |
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 seems that maybe xleft
and xright
should be set outside the loop in case xleft
and xright
have been swapped on a shared axes somehow? I assume the idea is for all the axes to be identical.
@l-johnston Thanks again for your work on this. On the dev call @anntzer and @efiring pointed out that a) this is the correct functionality, so please forgive my concern, b) this PR could likely be made a lot simpler by just calling |
I'm not sure it'd be so simple, as this is in the One possible way would be to update |
You can do something along the lines of set_xlim(...) if self is self.axes.xaxis else
set_ylim(...) if self is self.axes.yaxis else
set_zlim(...) if self is getattr(self.axes, "zaxis") else
(fall back on the old way of using set_view_interval) or try:
axis_name, = [k for k, v in self.axes._get_axis_map() if v is self]
except ValueError:
(fall back)
getattr(self, f"set_{axis_name}lim")(...) btw instead of set_x/y/zlim you can also use set_x/y/zbound which will auto-handle inverted axises for you. |
|
@jklymak I implemented @anntzer 's approach of using set_x/y/zbound, but this breaks 20 tests such as: def test_set_ticks_inverted():
fig, ax = plt.subplots()
ax.invert_xaxis()
ax.set_xticks([.3, .7])
> assert ax.get_xlim() == (1, 0)
E assert (0.7, 0.3) == (1, 0)
E At index 0 diff: 0.7 != 1
E Use -v to get the full diff
lib/matplotlib/tests/test_axes.py:6520: AssertionError |
Well, perhaps my suggestion was wrong, I didn't actually try it :) |
Well, I'm confused - does setting the xticks set the limits to the first and last tick or does it insert a margin? |
@jklymak setting ticks inserts some margin since the call to |
PR Summary
Closes #8946
Synchronization uses the approach implemented in PR #18308 and tests according to the one outlined in issue #8946.
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).