8000 Move IPython backend registration to Matplotlib · matplotlib/matplotlib@c457c55 · GitHub
[go: up one dir, main page]

Skip to content

Commit c457c55

Browse files
committed
Move IPython backend registration to Matplotlib
1 parent 5300bd6 commit c457c55

File tree

10 files changed

+458
-65
lines changed

10 files changed

+458
-65
lines changed

lib/matplotlib/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,14 +1208,18 @@ def use(backend, *, force=True):
12081208
backend names, which are case-insensitive:
12091209
12101210
- interactive backends:
1211-
GTK3Agg, GTK3Cairo, GTK4Agg, GTK4Cairo, MacOSX, nbAgg, QtAgg,
1212-
QtCairo, TkAgg, TkCairo, WebAgg, WX, WXAgg, WXCairo, Qt5Agg, Qt5Cairo
1211+
GTK3Agg, GTK3Cairo, GTK4Agg, GTK4Cairo, MacOSX, nbAgg, notebook, QtAgg,
1212+
QtCairo, TkAgg, TkCairo, WebAgg, WX, WXAgg, WXCairo, Qt5Agg, Qt5Cairo,
1213+
Qt6Agg, Qt6Cairo
12131214
12141215
- non-interactive backends:
12151216
agg, cairo, pdf, pgf, ps, svg, template
12161217
12171218
or a string of the form: ``module://my.module.name``.
12181219
1220+
notebook is a synonym for nbAgg, Qt6Agg for QtAgg, and Qt6Cairo for
1221+
QtCairo.
1222+
12191223
Switching to an interactive backend is not possible if an unrelated
12201224
event loop has already been started (e.g., switching to GTK3Agg if a
12211225
TkAgg window has already been opened). Switching to a non-interactive

lib/matplotlib/backend_bases.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,8 +1766,12 @@ def _fix_ipython_backend2gui(cls):
17661766
# `ipython --auto`). This cannot be done at import time due to
17671767
# ordering issues, so we do it when creating a canvas, and should only
17681768
# be done once per class (hence the `cache`).
1769-
if sys.modules.get("IPython") is None:
1769+
mod_ipython = sys.modules.get("IPython")
1770+
if mod_ipython is None or mod_ipython.version_info[:2] >= (8, 23):
1771+
# Use of backend2gui is not needed for IPython >= 8.23 as the
1772+
# functionality has been moved to Matplotlib.
17701773
return
1774+
17711775
import IPython
17721776
ip = IPython.get_ipython()
17731777
if not ip:
@@ -2030,9 +2034,9 @@ def _switch_canvas_and_return_print_method(self, fmt, backend=None):
20302034
canvas = None
20312035
if backend is not None:
20322036
# Return a specific canvas class, if requested.
2037+
from .backends.registry import backend_registry
20332038
canvas_class = (
2034-
importlib.import_module(cbook._backend_module_name(backend))
2035-
.FigureCanvas)
2039+
backend_registry.load_backend_module(backend).FigureCanvas)
20362040
if not hasattr(canvas_class, f"print_{fmt}"):
20372041
raise ValueError(
20382042
f"The {backend!r} backend does not support {fmt} output")

0 commit comments

Comments
 (0)
0