From 9b2f5a851c467537675dcc694a164ce05128e882 Mon Sep 17 00:00:00 2001 From: Ryan Clary <9618975+mrclary@users.noreply.github.com> Date: Mon, 20 May 2024 10:59:57 -0700 Subject: [PATCH] Matplotlib get_backend returns lowercase in version >=3.9.0. Also, inline backend is returned as "inline" instead of "modluel://..." --- spyder_kernels/console/kernel.py | 4 ++-- spyder_kernels/utils/mpl.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spyder_kernels/console/kernel.py b/spyder_kernels/console/kernel.py index 306d2afa..d626ca62 100644 --- a/spyder_kernels/console/kernel.py +++ b/spyder_kernels/console/kernel.py @@ -382,7 +382,7 @@ def get_matplotlib_backend(self): """Get current matplotlib backend.""" try: import matplotlib - return MPL_BACKENDS_TO_SPYDER[matplotlib.get_backend()] + return MPL_BACKENDS_TO_SPYDER[matplotlib.get_backend().lower()] except Exception: return None @@ -428,7 +428,7 @@ def get_mpl_interactive_backend(self): # equivalent to having the inline one. return 0 elif framework in mapping: - return MPL_BACKENDS_TO_SPYDER[mapping[framework]] + return MPL_BACKENDS_TO_SPYDER[mapping[framework].lower()] else: # This covers the case of other backends (e.g. Wx or Gtk) # which users can set interactively with the %matplotlib diff --git a/spyder_kernels/utils/mpl.py b/spyder_kernels/utils/mpl.py index 7927e49d..46b52607 100644 --- a/spyder_kernels/utils/mpl.py +++ b/spyder_kernels/utils/mpl.py @@ -27,11 +27,12 @@ # Mapping of matlotlib backends options to Spyder MPL_BACKENDS_TO_SPYDER = { - inline_backend: 0, - 'Qt5Agg': 2, - 'QtAgg': 2, # For Matplotlib 3.5+ - 'TkAgg': 3, - 'MacOSX': 4, + 'inline': 0, # For Matplotlib >=3.9 + inline_backend: 0, # For Matplotlib <3.9 + 'qt5agg': 2, + 'qtagg': 2, # For Matplotlib 3.5+ + 'tkagg': 3, + 'macosx': 4, }