From 09e4e62575d59741837d042654a0ce3fc23dfd07 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 13 Jul 2016 11:56:20 -0500 Subject: [PATCH] register IPython's eventloop integration in plt.install_repl_displayhook registers eventloop integration for IPython on setup, avoiding hangs when IPython hasn't been told about IPython prior to plotting. --- lib/matplotlib/pyplot.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index fa5ba35c35e6..2f57dd7e11e4 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -121,7 +121,8 @@ 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. + This works with IPython terminals and kernels, + as well as vanilla python shells. """ global _IP_REGISTERED global _INSTALL_FIG_OBSERVER @@ -154,6 +155,13 @@ def post_execute(): _IP_REGISTERED = post_execute _INSTALL_FIG_OBSERVER = False + + # trigger IPython's eventloop integration, if available + from IPython.core.pylabtools import backend2gui + + ipython_gui_name = backend2gui.get(get_backend()) + if ipython_gui_name: + ip.enable_gui(ipython_gui_name) else: _INSTALL_FIG_OBSERVER = True