Toolbars keep history if axes change (navtoolbar2 + toolmanager) #4857

Merged
merged 1 commit into from Jan 4, 2016

Conversation

Projects
None yet
4 participants
Contributor

KevKeating commented Aug 3, 2015

This is a fix for #2511. With this PR, the back, forward, and home buttons in the toolbar will continue to work even if the number of axes changes. I've implemented this fix in both the navtoolbar2 toolbar as well as the MEP22 toolmanager toolbar, so this PR essentially combines #3347 and fariza/matplotlib#5.

The PR adds a home_views dictionary that stores the initial views of all axes. If an axes object didn't exist when a view was created, then the initial view will be used for that axes in that view. Positions will only be restored if there is a position for all current axes objects. This avoids having newer axes overlap with older ones when clicking on back or home.

I've also removed toolbar.update() as an axobserver since it's no longer necessary. (I noticed that toolbar.update() was connected in all the backends except for Qt4, which explains the traceback I observed in #2511 when using Qt4.)

Member

fariza commented Aug 3, 2015

@KevKeating have you seen #4795 ?

Contributor

KevKeating commented Aug 3, 2015

I hadn't seen it, but I just took a look through it and it looks quite nice. It shouldn't be difficult to merge this PR with that one. Calls to _axes_view in this PR could simply be replaced with a call to a.get_view() instead, and

xmin, xmax, ymin, ymax = cur_lim
a.set_xlim((xmin, xmax))
a.set_ylim((ymin, ymax))

in _update_view in this PR could be replaced with a.set_view(cur_lim).

Contributor

KevKeating commented Aug 3, 2015

I just fixed a PEP8 issue in a docstring that Travis found. There was also a Python 2.6 failure that I'll look into soon.

Owner

jenshnielsen commented Aug 4, 2015

I think the python 2.6 failure was just a random Travis failure. I have restarted the test

Contributor

KevKeating commented Oct 2, 2015

Just updated this PR to use the new API from #4795.

Member

fariza commented Oct 11, 2015

@tacaswell do you think it is pertinent just make the changes in toolmanager so no new features appear in the old ToolbarNavigation

Owner

tacaswell commented Oct 12, 2015

@fariza I think it is fine to only put this into toolmanager, but will defer final judgement to you on this.

@fariza fariza commented on the diff Oct 13, 2015

lib/matplotlib/backend_tools.py
# Define Home
self.push_current()
- # Adding the clear method as axobserver, removes this burden from
- # the backend
- self.figure.add_axobserver(self.clear)
@fariza

fariza Oct 13, 2015

Member

@KevKeating
If you add one axes, and don't call any of the navigation methods, your views and possitions will be out of sync.
Somebody accessing the views, positions...
Why don't leave the axobserver and instead of calling clear, calling update_home_views?

@KevKeating

KevKeating Oct 26, 2015

Contributor

@fariza
Good point. I'll add update_home_views as an axobserver. Should I remove the ToolbarNavigation changes or leave those in?

Member

fariza commented Oct 26, 2015

@KevKeating I really think it is better if we keep this confined to ToolManager, so we don't have to deal with new features and its bugs inside something we want to deprecate.
Please remove the changes in NavigationToolbar2

Contributor

KevKeating commented Oct 26, 2015

Just pushed an update. update_home_views now runs as an axobserver. Since it's run when axes are added, it no longer needs to be run in push_current. I've also removed the NavigationToolbar2 changes.

@fariza fariza and 1 other commented on an outdated diff Oct 30, 2015

lib/matplotlib/backend_tools.py
# Define Home
self.push_current()
- # Adding the clear method as axobserver, removes this burden from
- # the backend
- self.figure.add_axobserver(self.clear)
-
- def clear(self, figure):
@fariza

fariza Oct 30, 2015

Member

Don't remove the clear method, it could be useful for other tools.
Update it to include the update_home_views

@fariza

fariza Dec 17, 2015

Member

@KevKeating I think the clear method comment that I made is the last thing needed before merge.

@KevKeating

KevKeating Dec 17, 2015

Contributor

Sorry, that completely slipped my mind. I'll update the diff soon.

@KevKeating

KevKeating Dec 18, 2015

Contributor

I just added clear back in with

self.home_views[figure].clear()
self.update_home_views()

added. That's the only change in this new commit.

@KevKeating KevKeating Toolbars keep history if axes change
b5506dc
Contributor

KevKeating commented Jan 4, 2016

I'm not sure what's going on with the test failure. It looks like assert_array_equal is raising an exception even though the tuples it's comparing are equal. (Both tuples are (0,0, 1.0), where each number is of type numpy.float64.) If I replace assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim) with assert ax_lst[0][1].get_xlim() == orig_xlim, then the test passes. Should I add that change to my branch?

Member

fariza commented Jan 4, 2016

@KevKeating Do you think it is related to your changes? I don't see how.

Contributor

KevKeating commented Jan 4, 2016

@fariza Me neither. I'm guessing that it's unrelated.

@fariza fariza added a commit that referenced this pull request Jan 4, 2016

@fariza fariza Merge pull request #4857 from KevKeating/iss2511-cmb
Toolbars keep history if axes change (navtoolbar2 + toolmanager)
c849398

@fariza fariza merged commit c849398 into matplotlib:master Jan 4, 2016

1 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
coverage/coveralls Coverage pending from Coveralls.io
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

tacaswell removed the needs_review label Jan 4, 2016

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