Skip to content

Commit

Permalink
use display instead of send_figure in inline backend hooks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
minrk committed Aug 9, 2012
1 parent 6c1d6d9 commit 1ea9ce2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions IPython/zmq/pylab/backend_inline.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1ea9ce2

Please sign in to comment.