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

Skip to content

Restore axes sharedness when unpickling. #11544

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

Merged
merged 1 commit into from
Jul 4, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 1, 2018

Alternative implementation of #10659, which addresses the issues raised in the comments.

Previously, pickling and unpickling shared axes would result in
axes sharing a ticker instance (because that's how shared axes
are set up), but without changes of one's xlims propagated to the
other. The reason is that that sharedness information is stored in
AxesBase._shared_x_axes, which does not get pickled together with the
Axes instance: the latter only has a textual reference "I am an instance
of AxesBase", so the Grouper information is lost.

this is the part of the implementation that changed

To keep the Grouper information valid, additionally pickle the current
group of shared axes together with the Axes, and restore that
information upon unpickling.

end of diff

PR Summary

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

Previously, pickling and unpickling shared axes would result in
axes sharing a ticker instance (because that's how shared axes
are set up), but without changes of one's xlims propagated to the
other.  The reason is that that sharedness information is stored in
AxesBase._shared_x_axes, which does *not* get pickled together with the
Axes instance: the latter only has a textual reference "I am an instance
of AxesBase", so the Grouper information is lost.

To keep the Grouper information valid, additionally pickle the current
group of shared axes together with the Axes, and restore that
information upon unpickling.
@anntzer anntzer added this to the v3.0 milestone Jul 1, 2018
@timhoffm
Copy link
Member

timhoffm commented Jul 1, 2018

So, is it correct that now

  1. Pickling and unpickling two shared axes shared axes is now fully transparent?

  2. Having two shared axes A, B and just pickling and unpickling B in the same session breaks the relation because B will have a new grouper?

Would be good enough for me. Do we have some place to document that you would always have to pickle the full set of shared axes together?

@anntzer
Copy link
Contributor Author

anntzer commented Jul 1, 2018

Pickling and unpickling two shared axes shared axes is now fully transparent?

To the best of my knowledge...

Having two shared axes A, B and just pickling and unpickling B in the same session breaks the relation because B will have a new grouper?

No, because there is a single grouper instance, unpickling B just readds its connected component to it (which is already there and doesn't change anything). Manually trying that (e.g. pickle.loads(pickle.dumps(ax_b))) works, too.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

I think this is right...

@jklymak jklymak merged commit d9d7ff1 into matplotlib:master Jul 4, 2018
@anntzer anntzer deleted the pickleshared2 branch July 4, 2018 18:12
@tacaswell
Copy link
Member

I am glad this ended up being much simpler than I expected.

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

Successfully merging this pull request may close these issues.

4 participants