Skip to content

Commit fb83117

Browse files
committed
Register figureoptions edits in views history.
Changing axes limits in views history is now taken into account by the views history navigation. The home position is now defined the first time the figure canvas is drawn (rather than the first time an edit button is selected), via a one-shot callback.
1 parent b13c68a commit fb83117

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from six.moves import xrange
4040

4141
from contextlib import contextmanager
42+
from functools import partial
4243
import importlib
4344
import io
4445
import itertools
@@ -2833,6 +2834,13 @@ def __init__(self, canvas):
28332834
self.mode = '' # a mode string for the status bar
28342835
self.set_history_buttons()
28352836

2837+
@partial(canvas.mpl_connect, 'draw_event')
2838+
def define_home(event):
2839+
self.push_current()
2840+
# The decorator sets `define_home` to the callback cid, so we can
2841+
# disconnect it after the first use.
2842+
canvas.mpl_disconnect(define_home)
2843+
28362844
def set_message(self, s):
28372845
"""Display a message on toolbar or in status bar."""
28382846

@@ -2982,11 +2990,6 @@ def press_pan(self, event):
29822990
return
29832991

29842992
x, y = event.x, event.y
2985-
2986-
# push the current view to define home if stack is empty
2987-
if self._views.empty():
2988-
self.push_current()
2989-
29902993
self._xypress = []
29912994
for i, a in enumerate(self.canvas.figure.get_axes()):
29922995
if (x is not None and y is not None and a.in_axes(event) and
@@ -3022,11 +3025,6 @@ def press_zoom(self, event):
30223025
return
30233026

30243027
x, y = event.x, event.y
3025-
3026-
# push the current view to define home if stack is empty
3027-
if self._views.empty():
3028-
self.push_current()
3029-
30303028
self._xypress = []
30313029
for i, a in enumerate(self.canvas.figure.get_axes()):
30323030
if (x is not None and y is not None and a.in_axes(event) and

lib/matplotlib/backends/qt_editor/figureoptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def apply_callback(data):
248248
# Redraw
249249
figure = axes.get_figure()
250250
figure.canvas.draw()
251+
figure.canvas.toolbar.push_current()
251252

252253
data = formlayout.fedit(datalist, title="Figure options", parent=parent,
253254
icon=get_icon('qt4_editor_options.svg'),

0 commit comments

Comments
 (0)