@@ -1553,6 +1553,20 @@ def _draw(renderer): raise Done(renderer)
15531553 return figure ._cachedRenderer
15541554
15551555
1556+ def _is_non_interactive_terminal_ipython (ip ):
1557+ """
1558+ Return whether we are in a a terminal IPython, but non interactive.
1559+
1560+ When in _terminal_ IPython, ip.parent will have and `interact` attribute,
1561+ if this attribute is False we do not setup eventloop integration as the
1562+ user will _not_ interact with IPython. In all other case (ZMQKernel, or is
1563+ interactive), we do.
1564+ """
1565+ return (hasattr (ip , 'parent' )
1566+ and (ip .parent is not None )
1567+ and getattr (ip .parent , 'interact' , None ) is False )
1568+
1569+
15561570class FigureCanvasBase :
15571571 """
15581572 The canvas the figure renders into.
@@ -1645,15 +1659,8 @@ def _fix_ipython_backend2gui(cls):
16451659 backend2gui_rif = {"qt5" : "qt" , "qt4" : "qt" , "gtk3" : "gtk3" ,
16461660 "wx" : "wx" , "macosx" : "osx" }.get (rif )
16471661 if backend2gui_rif :
1648- pt .backend2gui [get_backend ()] = backend2gui_rif
1649- # Work around pylabtools.find_gui_and_backend always reading from
1650- # rcParamsOrig.
1651- orig_origbackend = mpl .rcParamsOrig ["backend" ]
1652- try :
1653- mpl .rcParamsOrig ["backend" ] = mpl .rcParams ["backend" ]
1654- ip .enable_matplotlib ()
1655- finally :
1656- mpl .rcParamsOrig ["backend" ] = orig_origbackend
1662+ if _is_non_interactive_terminal_ipython (ip ):
1663+ ip .enable_gui (backend2gui_rif )
16571664
16581665 @contextmanager
16591666 def _idle_draw_cntx (self ):
0 commit comments