Skip to content
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

toolbar.update() breaks history #9974

Closed
Nodd opened this issue Dec 11, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@Nodd
Copy link
Contributor

commented Dec 11, 2017

Bug report

Bug summary

I'm looking for resetting the zoom and pan history of interactve browsing. Using toolbar.update() breaks the interactive history, it's not possible to go back to the previous axis state.

Code for reproduction

Run this code in python a console:

from matplotlib import pyplot as plt
f = plt.figure()
plt.plot([1, 2, 5])
plt.show(block=False)
f.canvas.toolbar._views._elements  # One element
f.canvas.toolbar._positions._elements  # One element
f.canvas.toolbar.update()
f.canvas.toolbar._views._elements  # Empty !
f.canvas.toolbar._positions._elements  # Empty !
# Zoom once
# Try to go back using the home button or back arrow

Actual outcome

The view doesn't change when pressing home button or back arrow

Expected outcome

I expect to be able to got back to the state the plot was in when f.canvas.toolbar.update() was called, but since the history is completely empty, there is no state to go back to. I think the current state should be added right after clearing the history. Is it possible to do it manually in the meantime ?

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version: 2.1.0-1
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.3
  • Jupyter version (if applicable):
  • Other libraries:
@Nodd

This comment has been minimized.

Copy link
Contributor Author

commented Dec 11, 2017

Quick update, this works:

f.canvas.toolbar.update()
f.canvas.toolbar.push_current()

@jklymak jklymak added this to the v2.2 milestone Dec 11, 2017

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Dec 11, 2017

Are you able to check this in Master? The behaviour here changed a fair bit to the point that ._views. doesn't exist anymore.

Right now what happens is update clears the _nav_stack. so you are right that there is no state. However, the push_current is now called if either zoom or pan are pressed (as of #9958
in master, not 2.1.1). So I think this is functionally fixed. If we do what you suggest (push_current on update) then two "Home" states will be defined. Given that you are doing things interactively, that could be a problem if you add plot elements. I think the current behaviour is correct.

Out of curiousity, why are you calling update anyways?

@Nodd

This comment has been minimized.

Copy link
Contributor Author

commented Dec 13, 2017

If I understand correctly the behavior will be wrong if zoom or pan were already pressed before update() ? In this case push_current will not be called for the inital state. I think that if push_current is called inside update but not when pressing zoom or pan there will alwas be a "Home" state but no duplicate state.

I will try to check with master but I don't think I will find the time soon.

In my case the matplotlib widget is embedded in a Qt application where some parameters can change. In that case the plot is redrawn and the view is reset, and the previous history has to be cleared so that the Home button sets the view to a useful state.

@ImportanceOfBeingErnest

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2018

It seems this SO question has a very similar issue. It would also be a use case scenario for why to call update.

I cannot reproduce with matplotlib 2.1.2, but it seems to me that the fix #9958 would rather break the working behaviour in version 2.1.2.

@jklymak

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2018

🤷‍♂️ If there is a replicable bug in 2.1.2 please open an issue or re-open this one. It doesn't sound like there is at this point, so I'll close.

@jklymak jklymak closed this Feb 5, 2018

@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.