matplotlib.backends.registry#

class matplotlib.backends.registry.BackendFilter(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Filter used with list_builtin()

Added in version 3.9.

INTERACTIVE = 0[source]#
NON_INTERACTIVE = 1[source]#
class matplotlib.backends.registry.BackendRegistry[source]#

Bases: object

Registry of backends available within Matplotlib.

This is the single source of truth for available backends.

All use of BackendRegistry should be via the singleton instance backend_registry which can be imported from matplotlib.backends.

Each backend has a name, a module name containing the backend code, and an optional GUI framework that must be running if the backend is interactive. There are three sources of backends: built-in (source code is within the Matplotlib repository), explicit module://some.backend syntax (backend is obtained by loading the module), or via an entry point (self-registering backend in an external package).

Added in version 3.9.

backend_for_gui_framework(framework)[source]#

Return the name of the backend corresponding to the specified GUI framework.

Parameters:
frameworkstr

GUI framework such as "qt".

Returns:
str or None

Backend name or None if GUI framework not recognised.

is_valid_backend(backend)[source]#

Return True if the backend name is valid, False otherwise.

A backend name is valid if it is one of the built-in backends or has been dynamically added via an entry point. Those beginning with module:// are always considered valid and are added to the current list of all backends within this function.

Even if a name is valid, it may not be importable or usable. This can only be determined by loading and using the backend module.

Parameters:
backendstr

Name of backend.

Returns:
bool

True if backend is valid, False otherwise.

list_all()[source]#

Return list of all known backends.

These include built-in backends and those obtained at runtime either from entry points or explicit module://some.backend syntax.

Entry points will be loaded if they haven't been already.

Returns:
list of str

Backend names.

list_builtin(filter_=None)[source]#

Return list of backends that are built into Matplotlib.

Parameters:
filter_BackendFilter, optional

Filter to apply to returned backends. For example, to return only non-interactive backends use BackendFilter.NON_INTERACTIVE.

Returns:
list of str

Backend names.

list_gui_frameworks()[source]#

Return list of GUI frameworks used by Matplotlib backends.

Returns:
list of str

GUI framework names.

load_backend_module(backend)[source]#

Load and return the module containing the specified backend.

Parameters:
backendstr

Name of backend to load.

Returns:
Module

Module containing backend.

resolve_backend(backend)[source]#

Return the backend and GUI framework for the specified backend name.

If the GUI framework is not yet known then it will be determined by loading the backend module and checking the FigureCanvas.required_interactive_framework attribute.

This function only loads entry points if they have not already been loaded and the backend is not built-in and not of module://some.backend format.

Parameters:
backendstr or None

Name of backend, or None to use the default backend.

Returns:
backendstr

The backend name.

frameworkstr or None

The GUI framework, which will be None for a backend that is non-interactive.

resolve_gui_or_backend(gui_or_backend)[source]#

Return the backend and GUI framework for the specified string that may be either a GUI framework or a backend name, tested in that order.

This is for use with the IPython %matplotlib magic command which may be a GUI framework such as %matplotlib qt or a backend name such as %matplotlib qtagg.

This function only loads entry points if they have not already been loaded and the backend is not built-in and not of module://some.backend format.

Parameters:
gui_or_backendstr or None

Name of GUI framework or backend, or None to use the default backend.

Returns:
backendstr

The backend name.

frameworkstr or None

The GUI framework, which will be None for a backend that is non-interactive.