diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 2120a0120749..31719b458807 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -215,12 +215,6 @@ def _get_backend_mod(): # will (re)import pyplot and then call switch_backend if we need to # resolve the auto sentinel) switch_backend(dict.__getitem__(rcParams, "backend")) - # Just to be safe. Interactive mode can be turned on without calling - # `plt.ion()` so register it again here. This is safe because multiple - # calls to `install_repl_displayhook` are no-ops and the registered - # function respects `mpl.is_interactive()` to determine if it should - # trigger a draw. - install_repl_displayhook() return _backend_mod @@ -311,6 +305,10 @@ class backend_mod(matplotlib.backend_bases._Backend): # See https://github.com/matplotlib/matplotlib/issues/6092 matplotlib.backends.backend = newbackend + # make sure the repl display hook is installed in case we become + # interactive + install_repl_displayhook() + def _warn_if_gui_out_of_main_thread(): if (_get_required_interactive_framework(_get_backend_mod()) diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index 0105c6f22d47..b376c1b54af3 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -335,3 +335,17 @@ def test_fallback_position(): axtest = plt.axes([0.2, 0.2, 0.5, 0.5], position=[0.1, 0.1, 0.8, 0.8]) np.testing.assert_allclose(axtest.bbox.get_points(), axref.bbox.get_points()) + + +def test_pylab_integration(): + IPython = pytest.importorskip("IPython") + mpl.testing.subprocess_run_helper( + IPython.start_ipython, + "--pylab", + "-c", + ";".join(( + "import matplotlib.pyplot as plt", + "assert plt._IP_REGISTERED is not None", + )), + timeout=60, + )