Show More
@@ -24,12 +24,13 b' from warnings import warn' | |||||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
25 |
|
25 | |||
26 | magic_gui_arg = magic_arguments.argument( |
|
26 | magic_gui_arg = magic_arguments.argument( | |
27 | 'gui', nargs='?', |
|
27 | "gui", | |
28 | help="""Name of the matplotlib backend to use such as 'qt' or 'widget'. |
|
28 | nargs="?", | |
|
29 | help="""Name of the matplotlib backend to use such as 'qt' or 'widget'. | |||
29 | If given, the corresponding matplotlib backend is used, |
|
30 | If given, the corresponding matplotlib backend is used, | |
30 | otherwise it will be matplotlib's default |
|
31 | otherwise it will be matplotlib's default | |
31 | (which you can set in your matplotlib config file). |
|
32 | (which you can set in your matplotlib config file). | |
32 | """ |
|
33 | """, | |
33 | ) |
|
34 | ) | |
34 |
|
35 | |||
35 |
|
36 | |||
@@ -93,11 +94,14 b' class PylabMagics(Magics):' | |||||
93 | args = magic_arguments.parse_argstring(self.matplotlib, line) |
|
94 | args = magic_arguments.parse_argstring(self.matplotlib, line) | |
94 | if args.list: |
|
95 | if args.list: | |
95 | from IPython.core.pylabtools import _matplotlib_manages_backends |
|
96 | from IPython.core.pylabtools import _matplotlib_manages_backends | |
|
97 | ||||
96 | if _matplotlib_manages_backends(): |
|
98 | if _matplotlib_manages_backends(): | |
97 | from matplotlib.backends.registry import backend_registry |
|
99 | from matplotlib.backends.registry import backend_registry | |
|
100 | ||||
98 | backends_list = backend_registry.list_all() |
|
101 | backends_list = backend_registry.list_all() | |
99 | else: |
|
102 | else: | |
100 | from IPython.core.pylabtools import backends |
|
103 | from IPython.core.pylabtools import backends | |
|
104 | ||||
101 | backends_list = list(backends.keys()) |
|
105 | backends_list = list(backends.keys()) | |
102 | print("Available matplotlib backends: %s" % backends_list) |
|
106 | print("Available matplotlib backends: %s" % backends_list) | |
103 | else: |
|
107 | else: |
@@ -44,7 +44,9 b' _deprecated_backends = {' | |||||
44 | # GUI support to activate based on the desired matplotlib backend. For the |
|
44 | # GUI support to activate based on the desired matplotlib backend. For the | |
45 | # most part it's just a reverse of the above dict, but we also need to add a |
|
45 | # most part it's just a reverse of the above dict, but we also need to add a | |
46 | # few others that map to the same GUI manually: |
|
46 | # few others that map to the same GUI manually: | |
47 | _deprecated_backend2gui = dict(zip(_deprecated_backends.values(), _deprecated_backends.keys())) |
|
47 | _deprecated_backend2gui = dict( | |
|
48 | zip(_deprecated_backends.values(), _deprecated_backends.keys()) | |||
|
49 | ) | |||
48 | # In the reverse mapping, there are a few extra valid matplotlib backends that |
|
50 | # In the reverse mapping, there are a few extra valid matplotlib backends that | |
49 | # map to the same GUI support |
|
51 | # map to the same GUI support | |
50 | _deprecated_backend2gui["GTK"] = _deprecated_backend2gui["GTKCairo"] = "gtk" |
|
52 | _deprecated_backend2gui["GTK"] = _deprecated_backend2gui["GTKCairo"] = "gtk" | |
@@ -279,7 +281,7 b' def select_figure_formats(shell, formats, **kwargs):' | |||||
279 |
|
281 | |||
280 | [ f.pop(Figure, None) for f in shell.display_formatter.formatters.values() ] |
|
282 | [ f.pop(Figure, None) for f in shell.display_formatter.formatters.values() ] | |
281 | mplbackend = matplotlib.get_backend().lower() |
|
283 | mplbackend = matplotlib.get_backend().lower() | |
282 |
if mplbackend in ( |
|
284 | if mplbackend in ("nbagg", "ipympl", "widget", "module://ipympl.backend_nbagg"): | |
283 | formatter = shell.display_formatter.ipython_display_formatter |
|
285 | formatter = shell.display_formatter.ipython_display_formatter | |
284 | formatter.for_type(Figure, _reshow_nbagg_figure) |
|
286 | formatter.for_type(Figure, _reshow_nbagg_figure) | |
285 |
|
287 | |||
@@ -330,15 +332,16 b' def find_gui_and_backend(gui=None, gui_select=None):' | |||||
330 | """ |
|
332 | """ | |
331 |
|
333 | |||
332 | import matplotlib |
|
334 | import matplotlib | |
|
335 | ||||
333 | if _matplotlib_manages_backends(): |
|
336 | if _matplotlib_manages_backends(): | |
334 | backend_registry = matplotlib.backends.registry.backend_registry |
|
337 | backend_registry = matplotlib.backends.registry.backend_registry | |
335 |
|
338 | |||
336 | # gui argument may be a gui event loop or may be a backend name. |
|
339 | # gui argument may be a gui event loop or may be a backend name. | |
337 | if gui in ("auto", None): |
|
340 | if gui in ("auto", None): | |
338 |
backend = matplotlib.rcParamsOrig[ |
|
341 | backend = matplotlib.rcParamsOrig["backend"] | |
339 | backend, gui = backend_registry.resolve_backend(backend) |
|
342 | backend, gui = backend_registry.resolve_backend(backend) | |
340 | else: |
|
343 | else: | |
341 |
|
|
344 | backend, gui = backend_registry.resolve_gui_or_backend(gui) | |
342 |
|
345 | |||
343 | return gui, backend |
|
346 | return gui, backend | |
344 |
|
347 | |||
@@ -347,6 +350,7 b' def find_gui_and_backend(gui=None, gui_select=None):' | |||||
347 | has_unified_qt_backend = mpl_version_info >= (3, 5) |
|
350 | has_unified_qt_backend = mpl_version_info >= (3, 5) | |
348 |
|
351 | |||
349 | from IPython.core.pylabtools import backends |
|
352 | from IPython.core.pylabtools import backends | |
|
353 | ||||
350 | backends_ = dict(backends) |
|
354 | backends_ = dict(backends) | |
351 | if not has_unified_qt_backend: |
|
355 | if not has_unified_qt_backend: | |
352 | backends_["qt"] = "qt5agg" |
|
356 | backends_["qt"] = "qt5agg" | |
@@ -466,5 +470,6 b' def configure_inline_support(shell, backend):' | |||||
466 |
|
470 | |||
467 | def _matplotlib_manages_backends(): |
|
471 | def _matplotlib_manages_backends(): | |
468 | import matplotlib |
|
472 | import matplotlib | |
|
473 | ||||
469 | mpl_version_info = getattr(matplotlib, "__version_info__", (0, 0)) |
|
474 | mpl_version_info = getattr(matplotlib, "__version_info__", (0, 0)) | |
470 | return mpl_version_info >= (3, 9) |
|
475 | return mpl_version_info >= (3, 9) |
@@ -31,7 +31,7 b' from IPython.terminal import pt_inputhooks' | |||||
31 |
|
31 | |||
32 | gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases)) |
|
32 | gui_keys = tuple(sorted(pt_inputhooks.backends) + sorted(pt_inputhooks.aliases)) | |
33 |
|
33 | |||
34 | backend_keys = [] |
|
34 | backend_keys: list[str] = [] | |
35 |
|
35 | |||
36 | shell_flags = {} |
|
36 | shell_flags = {} | |
37 |
|
37 |
General Comments 0
You need to be logged in to leave comments.
Login now