Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix for shared axes diverging after setting tick markers #10651

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 84 commits into from

Conversation

shaynair
Copy link

@shaynair shaynair commented Mar 2, 2018

PR Summary

This fixes issue #8946.
It adds code to methods including set_xticks() and set_yticks(), which originally did not immediately update the shared axes. This led to axes having diverging get_xlim(), producing a wrong plot.

Example plot:
https://i.imgur.com/jipvFh3.png

Associated code snippet to reproduce the above plot:

import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(2, sharex=True)
ax1.plot(range(0, 10), range(0, 10))
ax2.plot(range(0, 10), range(0, 10))
plt.xticks(range(0, 30))
plt.show()

The two plots should be identical as they share the x-axis, but clearly aren't. This is a fix for this.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way


g = self.get_shared_x_axes()
for ax in g.get_siblings(self):
ax.xaxis.set_ticks(ticks, minor=minor)
Copy link
Member

Choose a reason for hiding this comment

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

Given how sharing works, I don't think you need all these "set_ticks" lines. I suspect that simply setting 'ax.stale = True' is enough. Would you try that, please?

Copy link
Author

Choose a reason for hiding this comment

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

I just tried it (commenting line 3209). Unfortunately doing that fails the automated test I created, so it wouldn't fix the issue.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you. Still, I'm pretty sure that calling set_ticks is not the right thing to do here. It is breaking part of the sharing connection by giving the axes different instances of the Locators. Instead, it looks like what is needed is synchronization of the view_interval after it was changed in the call to set_ticks. Logically, it seems like sharing should include the viewLim directly, but it doesn't, so when the viewLim is changed, the other axes need to be notified.

jklymak and others added 12 commits March 2, 2018 15:25
so don't rely on the 3rd party version.

Also replace py.test by pytest in the docs (recommended since pytest
3.0, https://docs.pytest.org/en/latest/changelog.html#id281; we require
pytest>=3.1 anyways).

Also delete tox.ini which is clearly outdated.
Add a link from the examples to the user's guide.

Clarify that the weakref behavior only affects *methods* used as
callbacks, not free functions.
…strainedlayout

FIX/ENH CL: Allow single parent colorbar w/ gridspec layout
Currently, Matplotlib reuses axes when add_axes() is called a second
time with the same arguments.  This behavior is deprecated since 2.1.

However we forgot to deprecate the same behavior in gca(), so we can't
remove that behavior yet.

Also cleanup docstrings of Stack class.  Also,
process_projection_requirements cannot modify the outer kwargs (because
`**kwargs` is always a copy), so remove the incorrect note regarding the
need for copies.
…stimestamp

ENH: check `.values` in more places
tacaswell and others added 21 commits March 4, 2018 14:33
…nedlayout

PRF: Speed up constrained layout
Matplotlib.nib was used by the old cocoaagg backend (ef8e81e) which has
been deleted a while ago.
figure_enter_event uses now LocationEvent instead of Event. Fix issue matplotlib#9812.
Anything (approximately) starting with two underscores, or an underscore
and a capital letter is reserved in the C++ standard.
Python 3 always uses the new buffer protocol.
It's still not closed, but at least we can reference it later.
Remove Python 2 code from C extensions
Some py3fication for matplotlib/__init__, setupext.
@shaynair
Copy link
Author

shaynair commented Mar 5, 2018

Thanks for the feedback @efiring, just a few concerns:

  • Would the auto parameter also be delegated to set_view_interval since it also needs to be propagated to the shared axes?
  • I'm having trouble making Axis3D compatible with the set_view_interval change. Axis3D uses v_interval whereas Axes3D.set_xlim uses xy_viewLim.intervalx which are different. How would I add the emit parameter to Axis3D.set_view_interval without it breaking previous test cases? And how would it be called from Axes3D.set_xlim?

@shaynair
Copy link
Author

shaynair commented Mar 5, 2018

Closed this due to the commit history being broken.

@shaynair
Copy link
Author

shaynair commented Mar 9, 2018

This pull request is updated here: #10691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.