Skip to content

Keep track of axes in interactive navigation. #9359

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 2 commits into from
Oct 30, 2017

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Oct 11, 2017

xref #9358.
@DeadParrot can you check that this patch fixes the issue for you?

I believe the old (2.0) code only "worked" if the axes you delay-added happened to have the same limits as the original ones (otherwise where did the info for the new axes get pushed?).

May want to switch to using weakrefs as preventing axes from being gc'd can be quite expensive...

EDIT: second commit switches to weakrefs.

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

@DeadParrot
Copy link

@anntzer this seems to eliminate the problem reported in #9358. I have not given it wider testing, of course.

Thanks for the quick action!

@anntzer
Copy link
Contributor Author

anntzer commented Oct 11, 2017

Did you try the second commit (which should avoid some bad memory leaks)?

@DeadParrot
Copy link

@anntzer no, I was too quick to pick that up. And I wouldn't have noticed leaks anyway. But if you need me to try it I can. I'm also happy to try the finished PR.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 11, 2017

Please do.

@tacaswell tacaswell added this to the 2.1.1 (next bug fix release) milestone Oct 11, 2017
@anntzer
Copy link
Contributor Author

anntzer commented Oct 11, 2017

Looking at this again I actually think the semantics of the home button are not very well defined when you start dynamically adding and removing axes (what do you do if the original axes are not there anymore?). This PR takes the view that we just don't do anything if an axes had been removed, and leave access that were not present as is (so one should strive to reuse axes if you want to keep the navigation information available). The old approach was to match axes by their index, which seems definitely more brittle once you start swapping axes around...

@DeadParrot
Copy link

@anntzer I will try to test the patch within the next couple of hours -- tied up at the moment.

I didn't write the original code I'm working with but I don't think it is dynamically adding/removing axes. Looks like it just resets the x/y limits and the labels and reuses everything. I assume this was an attempt to be more efficient -- maybe that doesn't actually pay. When you load a new plot it should be as if you discarded and created a new plot object from the user's point of view, so the semantics of the Home, Back, etc. buttons seem to be well defined. The reported bug appears when using the same axes updated in this way to plot a new set of curves. I dumped the value of _pos during zoom/unzoom operations to isolate the problem.

@anntzer
Copy link
Contributor Author

anntzer commented Oct 11, 2017

The problem is if you started with just one axes and then dynamically add another one (but keep the first one too): do we drop the nav info for the first axes (i.e. is home defined by where the first axes actually started, or by where it is at the time the second axes is added)? I don't have a very strong opinion there (other than considering that matching by index is definitely brittle in this case). @tacaswell want to comment?

@DeadParrot
Copy link

@anntzer I tried the revised (cffeef0) patch and it seems to be OK wrt the zoom/pan stack issue.

@2sn
Copy link

2sn commented Oct 11, 2017

I confirm this also fixed the problem I had as noted in #9358.

@2sn 2sn mentioned this pull request Oct 24, 2017
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Oct 24, 2017
@tacaswell
Copy link
Member

This is milestoned for the next bug fix release which will be tagged when everything is merged. This PR is currently waiting for review.

@2sn Could you do a careful code review of these changes? That will help expedite the process.

@@ -2799,19 +2797,24 @@ def __init__(self, canvas):
self.set_history_buttons()

@partial(canvas.mpl_connect, 'draw_event')
Copy link
Contributor

@dopplershift dopplershift Oct 30, 2017

Choose a reason for hiding this comment

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

So we're processing the navigation stack on every draw event? I'm concerned about potential performance of all the extra set and stuff. I realize we're already slow, but kinda hoping to not make things worse.

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Alright @tacaswell convinced me that this isn't going to be the slowest part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants