Skip to content

Commit

Permalink
Fix/mpl integration (#14128)
Browse files Browse the repository at this point in the history
- Closes matplotlib/matplotlib#17454
- fixes qt5/qt6 confusion
  • Loading branch information
Carreau committed Aug 28, 2023
2 parents a4d77b4 + 97191eb commit 175d52c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 17 additions & 9 deletions IPython/core/pylabtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"qt4": "Qt4Agg",
"qt5": "Qt5Agg",
"qt6": "QtAgg",
"qt": "Qt5Agg",
"qt": "QtAgg",
"osx": "MacOSX",
"nbagg": "nbAgg",
"webagg": "WebAgg",
Expand Down Expand Up @@ -53,8 +53,8 @@
# supports either Qt5 or Qt6 and the IPython qt event loop support Qt4, Qt5,
# and Qt6.
backend2gui["QtAgg"] = "qt"
backend2gui["Qt4Agg"] = "qt"
backend2gui["Qt5Agg"] = "qt"
backend2gui["Qt4Agg"] = "qt4"
backend2gui["Qt5Agg"] = "qt5"

# And some backends that don't need GUI integration
del backend2gui["nbAgg"]
Expand Down Expand Up @@ -208,10 +208,12 @@ def mpl_execfile(fname,*where,**kw):

#print '*** Matplotlib runner ***' # dbg
# turn off rendering until end of script
is_interactive = matplotlib.rcParams['interactive']
matplotlib.interactive(False)
safe_execfile(fname,*where,**kw)
matplotlib.interactive(is_interactive)
with matplotlib.rc_context({"interactive": False}):
safe_execfile(fname, *where, **kw)

if matplotlib.is_interactive():
plt.show()

# make rendering call now, if the user tried to do it
if plt.draw_if_interactive.called:
plt.draw()
Expand Down Expand Up @@ -317,9 +319,15 @@ def find_gui_and_backend(gui=None, gui_select=None):

import matplotlib

has_unified_qt_backend = getattr(matplotlib, "__version_info__", (0, 0)) >= (3, 5)

backends_ = dict(backends)
if not has_unified_qt_backend:
backends_["qt"] = "qt5agg"

if gui and gui != 'auto':
# select backend based on requested gui
backend = backends[gui]
backend = backends_[gui]
if gui == 'agg':
gui = None
else:
Expand All @@ -336,7 +344,7 @@ def find_gui_and_backend(gui=None, gui_select=None):
# ones allowed.
if gui_select and gui != gui_select:
gui = gui_select
backend = backends[gui]
backend = backends_[gui]

return gui, backend

Expand Down
4 changes: 2 additions & 2 deletions IPython/core/tests/test_pylabtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def act_mpl(backend):
# Save rcParams since they get modified
self._saved_rcParams = matplotlib.rcParams
self._saved_rcParamsOrig = matplotlib.rcParamsOrig
matplotlib.rcParams = dict(backend='Qt4Agg')
matplotlib.rcParamsOrig = dict(backend='Qt4Agg')
matplotlib.rcParams = dict(backend="QtAgg")
matplotlib.rcParamsOrig = dict(backend="QtAgg")

# Mock out functions
self._save_am = pt.activate_matplotlib
Expand Down

0 comments on commit 175d52c

Please sign in to comment.