From 610c61145d846d68634c32a7223518dbfcdeb162 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 8 Aug 2012 21:55:12 -0700 Subject: [PATCH] use display instead of send_figure in inline backend hooks This lets custom display functions (e.g. HTML) be used without any extra changes (see #2234). possible downsides: * The previous code guarantees that only one format is published. If multiple figure formatters are registered, display will send them all. * If people for some reason disable the type-printers, then they will display the automatic figure display. Neither of these cases can come up unless people are messing with the formatters, and I think the first is actually an improvement. --- IPython/zmq/pylab/backend_inline.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/IPython/zmq/pylab/backend_inline.py b/IPython/zmq/pylab/backend_inline.py index 469d74ca9cb..ddad82c8230 100644 --- a/IPython/zmq/pylab/backend_inline.py +++ b/IPython/zmq/pylab/backend_inline.py @@ -15,6 +15,7 @@ # Local imports. from IPython.config.configurable import SingletonConfigurable +from IPython.core.display import display from IPython.core.displaypub import publish_display_data from IPython.core.pylabtools import print_figure, select_figure_format from IPython.utils.traitlets import Dict, Instance, CaselessStrEnum, CBool @@ -102,7 +103,7 @@ def show(close=None): close = InlineBackend.instance().close_figures try: for figure_manager in Gcf.get_all_fig_managers(): - send_figure(figure_manager.canvas.figure) + display(figure_manager.canvas.figure) finally: show._to_draw = [] if close: @@ -138,7 +139,7 @@ def draw_if_interactive(): if not hasattr(fig, 'show'): # Queue up `fig` for display - fig.show = lambda *a: send_figure(fig) + fig.show = lambda *a: display(fig) # If matplotlib was manually set to non-interactive mode, this function # should be a no-op (otherwise we'll generate duplicate plots, since a user @@ -191,7 +192,7 @@ def flush_figures(): active = set([fm.canvas.figure for fm in Gcf.get_all_fig_managers()]) for fig in [ fig for fig in show._to_draw if fig in active ]: try: - send_figure(fig) + display(fig) except Exception as e: # safely show traceback if in IPython, else raise try: