Skip to content

toolbar.update() breaks history #9974

Closed

Description

@Nodd

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:

Activity

  1. Nodd commented on Dec 11, 2017

    @Nodd
    ContributorAuthor

    Quick update, this works:

    f.canvas.toolbar.update()
    f.canvas.toolbar.push_current()
  2. added this to the milestone on Dec 11, 2017
  3. jklymak commented on Dec 11, 2017

    @jklymak
    Member

    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?

  4. Nodd commented on Dec 13, 2017

    @Nodd
    ContributorAuthor

    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.

  5. ImportanceOfBeingErnest commented on Feb 5, 2018

    @ImportanceOfBeingErnest
    Member

    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.

  6. jklymak commented on Feb 5, 2018

    @jklymak
    Member

    🤷‍♂️ 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.

  7. modified the milestones: , v2.2.0 on Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions