@@ -1553,6 +1553,20 @@ def _draw(renderer): raise Done(renderer)
1553
1553
return figure ._cachedRenderer
1554
1554
1555
1555
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
+
1556
1570
class FigureCanvasBase :
1557
1571
"""
1558
1572
The canvas the figure renders into.
@@ -1645,15 +1659,8 @@ def _fix_ipython_backend2gui(cls):
1645
1659
backend2gui_rif = {"qt5" : "qt" , "qt4" : "qt" , "gtk3" : "gtk3" ,
1646
1660
"wx" : "wx" , "macosx" : "osx" }.get (rif )
1647
1661
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 )
1657
1664
1658
1665
@contextmanager
1659
1666
def _idle_draw_cntx (self ):
0 commit comments