diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index fccf69e6e628..75090a61cbbb 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -56,6 +56,11 @@ def _stale_figure_callback(self, val): self.figure.stale = val +def _stale_canvas_callback(self, val): + if rcParams['interactive'] and self.canvas is not None and val: + self.canvas.draw_idle() + + class AxesStack(Stack): """ Specialization of the Stack to handle all tracking of Axes in a Figure. @@ -352,6 +357,11 @@ def __init__(self, self._axstack = AxesStack() # track all figure axes and current axes self.clf() self._cachedRenderer = None + self.stale_callback = Figure._stale_callback + + def _stale_callback(self, val): + if val and self.canvas is not None: + self.canvas.stale = val # TODO: I'd like to dynamically add the _repr_html_ method # to the figure in the right context, but then IPython doesn't @@ -560,7 +570,7 @@ def set_canvas(self, canvas): ACCEPTS: a FigureCanvas instance """ self.canvas = canvas - self.stale = True + self.stale_callback = _stale_canvas_callback def hold(self, b=None): """ diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 07875554cf75..ceed02c0bba3 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -108,84 +108,6 @@ def _backend_selection(): from matplotlib.backends import pylab_setup _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() -_IP_REGISTERED = None -_INSTALL_FIG_OBSERVER = False - -def install_repl_displayhook(): - """ - Install a repl display hook so that any stale figure are automatically - redrawn when control is returned to the repl. - - This works with both IPython terminals and vanilla python shells. - """ - global _IP_REGISTERED - global _INSTALL_FIG_OBSERVER - - class _NotIPython(Exception): - pass - - # see if we have IPython hooks around, if use them - - try: - from IPython import get_ipython - ip = get_ipython() - if ip is None: - raise _NotIPython() - - if _IP_REGISTERED: - return - - def post_execute(): - if matplotlib.is_interactive(): - draw_all() - - # IPython >= 2 - try: - ip.events.register('post_execute', post_execute) - except AttributeError: - # IPython 1.x - ip.register_post_execute(post_execute) - - _IP_REGISTERED = post_execute - _INSTALL_FIG_OBSERVER = False - - # import failed or ipython is not running - except (ImportError, _NotIPython): - _INSTALL_FIG_OBSERVER = True - - -def uninstall_repl_displayhook(): - """ - Uninstalls the matplotlib display hook. - - .. warning - - Need IPython >= 2 for this to work. For IPython < 2 will raise a - ``NotImplementedError`` - - .. warning - - If you are using vanilla python and have installed another - display hook this will reset ``sys.displayhook`` to what ever - function was there when matplotlib installed it's displayhook, - possibly discarding your changes. - """ - global _IP_REGISTERED - global _INSTALL_FIG_OBSERVER - if _IP_REGISTERED: - from IPython import get_ipython - ip = get_ipython() - try: - ip.events.unregister('post_execute', _IP_REGISTERED) - except AttributeError: - raise NotImplementedError("Can not unregister events " - "in IPython < 2.0") - _IP_REGISTERED = None - - if _INSTALL_FIG_OBSERVER: - _INSTALL_FIG_OBSERVER = False - - draw_all = _pylab_helpers.Gcf.draw_all @@ -245,13 +167,11 @@ def isinteractive(): def ioff(): 'Turn interactive mode off.' matplotlib.interactive(False) - uninstall_repl_displayhook() def ion(): 'Turn interactive mode on.' matplotlib.interactive(True) - install_repl_displayhook() def pause(interval): @@ -532,16 +452,6 @@ def make_active(event): fig = figManager.canvas.figure fig.number = num - # make sure backends (inline) that we don't ship that expect this - # to be called in plotting commands to make the figure call show - # still work. There is probably a better way to do this in the - # FigureManager base class. - if matplotlib.is_interactive(): - draw_if_interactive() - - if _INSTALL_FIG_OBSERVER: - fig.stale_callback = _auto_draw_if_interactive - return figManager.canvas.figure @@ -2494,13 +2404,6 @@ def spy(Z, precision=0, marker=None, markersize=None, aspect='equal', hold=None, sci(ret) return ret -# just to be safe. Interactive mode can be turned on without -# calling `plt.ion()` so register it again here. -# This is safe because multiple calls to `install_repl_displayhook` -# are no-ops and the registered function respect `mpl.is_interactive()` -# to determine if they should trigger a draw. -install_repl_displayhook() - ################# REMAINING CONTENT GENERATED BY boilerplate.py ##############