diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index bca46679d5f8..3d0e9f583319 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -39,6 +39,7 @@ from six.moves import xrange from contextlib import contextmanager +from functools import partial import importlib import io import itertools @@ -2833,6 +2834,13 @@ def __init__(self, canvas): self.mode = '' # a mode string for the status bar self.set_history_buttons() + @partial(canvas.mpl_connect, 'draw_event') + def define_home(event): + self.push_current() + # The decorator sets `define_home` to the callback cid, so we can + # disconnect it after the first use. + canvas.mpl_disconnect(define_home) + def set_message(self, s): """Display a message on toolbar or in status bar.""" @@ -2982,11 +2990,6 @@ def press_pan(self, event): return x, y = event.x, event.y - - # push the current view to define home if stack is empty - if self._views.empty(): - self.push_current() - self._xypress = [] for i, a in enumerate(self.canvas.figure.get_axes()): 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): return x, y = event.x, event.y - - # push the current view to define home if stack is empty - if self._views.empty(): - self.push_current() - self._xypress = [] for i, a in enumerate(self.canvas.figure.get_axes()): if (x is not None and y is not None and a.in_axes(event) and diff --git a/lib/matplotlib/backends/qt_editor/figureoptions.py b/lib/matplotlib/backends/qt_editor/figureoptions.py index 9b34f2251da6..af9feaf5e5c6 100644 --- a/lib/matplotlib/backends/qt_editor/figureoptions.py +++ b/lib/matplotlib/backends/qt_editor/figureoptions.py @@ -47,6 +47,7 @@ def figure_edit(axes, parent=None): sep = (None, None) # separator # Get / General + # Cast to builtin floats as they have nicer reprs. xmin, xmax = map(float, axes.get_xlim()) ymin, ymax = map(float, axes.get_ylim()) general = [('Title', axes.get_title()), @@ -177,6 +178,9 @@ def prepare_data(d, init): def apply_callback(data): """This function will be called to apply changes""" + orig_xlim = axes.get_xlim() + orig_ylim = axes.get_ylim() + general = data.pop(0) curves = data.pop(0) if has_curve else [] images = data.pop(0) if has_image else [] @@ -248,6 +252,8 @@ def apply_callback(data): # Redraw figure = axes.get_figure() figure.canvas.draw() + if not (axes.get_xlim() == orig_xlim and axes.get_ylim() == orig_ylim): + figure.canvas.toolbar.push_current() data = formlayout.fedit(datalist, title="Figure options", parent=parent, icon=get_icon('qt4_editor_options.svg'),