From fb8d77353e278c1af252cd3dff5447f6029b69c2 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 20 Mar 2023 10:04:52 -0400 Subject: [PATCH] Backport PR #25496: BUG: fix IPython's %pylab mode detection --- lib/matplotlib/backend_bases.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 6532355f7efe..d2ad4f0efdad 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2898,8 +2898,8 @@ def pyplot_show(cls, *, block=None): # Hack: Are we in IPython's %pylab mode? In pylab mode, IPython # (>= 0.10) tacks a _needmain attribute onto pyplot.show (always # set to False). - ipython_pylab = hasattr( - getattr(sys.modules.get("pyplot"), "show", None), "_needmain") + pyplot_show = getattr(sys.modules.get("matplotlib.pyplot"), "show", None) + ipython_pylab = hasattr(pyplot_show, "_needmain") block = not ipython_pylab and not is_interactive() if block: cls.start_main_loop() @@ -3613,8 +3613,8 @@ def show(cls, *, block=None): # Hack: Are we in IPython's %pylab mode? In pylab mode, IPython # (>= 0.10) tacks a _needmain attribute onto pyplot.show (always # set to False). - ipython_pylab = hasattr( - getattr(sys.modules.get("pyplot"), "show", None), "_needmain") + pyplot_show = getattr(sys.modules.get("matplotlib.pyplot"), "show", None) + ipython_pylab = hasattr(pyplot_show, "_needmain") block = not ipython_pylab and not is_interactive() if block: cls.mainloop()