Select the backend used for rendering and GUI integration.
The backend to switch to. This can either be one of the standard backend names, which are case-insensitive:
or a string of the form: module://my.module.name
.
Switching to an interactive backend is not possible if an unrelated event loop has already been started (e.g., switching to GTK3Agg if a TkAgg window has already been opened). Switching to a non-interactive backend is always possible.
If True (the default), raise an ImportError
if the backend cannot be set up (either because it fails to import, or because an incompatible GUI interactive framework is already running); if False, silently ignore the failure.
See also
Return the name of the current backend.
See also
Set whether to redraw after every plotting command (e.g. pyplot.xlabel
).
Return whether to redraw after every plotting command.
Note
This function is only intended for use in backends. End users should use pyplot.isinteractive
instead.
A dictionary object including validation.
Validating functions are defined and associated with rc parameters in matplotlib.rcsetup
.
The list of rcParams is:
See also
Return the subset of this RcParams dictionary whose keys match, using re.search()
, the given pattern
.
Note
Changes to the returned dictionary are not propagated to the parent RcParams dictionary.
Return a context manager for temporarily changing rcParams.
The rcParams to temporarily set.
A file with Matplotlib rc settings. If both fname and rc are given, settings from rc take precedence.
See also
Passing explicit values via a dict:
with mpl.rc_context({'interactive': False}): fig, ax = plt.subplots() ax.plot(range(3), range(3)) fig.savefig('example.png') plt.close(fig)
Loading settings from a file:
with mpl.rc_context(fname='print.rc'): plt.plot(x, y) # uses 'print.rc'
Set the current rcParams
. group is the grouping for the rc, e.g., for lines.linewidth
the group is lines
, for axes.facecolor
, the group is axes
, and so on. Group may also be a list or tuple of group names, e.g., (xtick, ytick). kwargs is a dictionary attribute name/value pairs, e.g.,:
rc('lines', linewidth=2, color='r')
sets the current rcParams
and is equivalent to:
rcParams['lines.linewidth'] = 2 rcParams['lines.color'] = 'r'
The following aliases are available to save typing for interactive users:
Alias | Property |
---|---|
'lw' | 'linewidth' |
'ls' | 'linestyle' |
'c' | 'color' |
'fc' | 'facecolor' |
'ec' | 'edgecolor' |
'mew' | 'markeredgewidth' |
'aa' | 'antialiased' |
Thus you could abbreviate the above call as:
rc('lines', lw=2, c='r')
Note you can use python's kwargs dictionary facility to store dictionaries of default parameters. e.g., you can customize the font rc as follows:
font = {'family' : 'monospace', 'weight' : 'bold', 'size' : 'larger'} rc('font', **font) # pass in the font dict as kwargs
This enables you to easily switch between several configurations. Use matplotlib.style.use('default')
or rcdefaults()
to restore the default rcParams
after changes.
Similar functionality is available by using the normal dict interface, i.e. rcParams.update({"lines.linewidth": 2, ...})
(but rcParams.update
does not support abbreviations or grouping).
Restore the rcParams
from Matplotlib's internal default style.
Style-blacklisted rcParams
(defined in matplotlib.style.core.STYLE_BLACKLIST
) are not updated.
See also
matplotlib.rc_file_defaults
Restore the rcParams
from the rc file originally loaded by Matplotlib.
matplotlib.style.use
Use a specific style file. Call style.use('default')
to restore the default style.
Restore the rcParams
from the original rc file loaded by Matplotlib.
Style-blacklisted rcParams
(defined in matplotlib.style.core.STYLE_BLACKLIST
) are not updated.
Update rcParams
from file.
Style-blacklisted rcParams
(defined in matplotlib.style.core.STYLE_BLACKLIST
) are not updated.
A file with Matplotlib rc settings.
If True, initialize with default parameters before updating with those in the given file. If False, the current configuration persists and only the parameters specified in the file are updated.
Construct a RcParams
instance from the default Matplotlib rc file.
Construct a RcParams
from file fname.
A file with Matplotlib rc settings.
If True, raise an error when the parser fails to convert a parameter.
If True, initialize with default parameters before updating with those in the given file. If False, the configuration class only contains the parameters specified in the file. (Useful for updating dicts.)
Return the string path of the configuration directory.
The directory is chosen as follows:
$XDG_CONFIG_HOME
, if defined, or $HOME/.config
. On other platforms, choose $HOME/.matplotlib
.Get the location of the config file.
The file location is determined in the following order
$PWD/matplotlibrc
$MATPLOTLIBRC
if it is not a directory$MATPLOTLIBRC/matplotlibrc
$MPLCONFIGDIR/matplotlibrc
$XDG_CONFIG_HOME/matplotlib/matplotlibrc
(if $XDG_CONFIG_HOME
is defined)$HOME/.config/matplotlib/matplotlibrc
(if $XDG_CONFIG_HOME
is not defined)$HOME/.matplotlib/matplotlibrc
if $HOME
is defined$MATPLOTLIBDATA/matplotlibrc
, which should always exist.Return the path to Matplotlib data.
Set Matplotlib's root logger and root logger handler level, creating the handler if it does not exist yet.
Typically, one should call set_loglevel("info")
or set_loglevel("debug")
to get additional debugging information.
The log level of the handler.
The first time this function is called, an additional handler is attached to Matplotlib's root handler; this handler is reused every time and this function simply manipulates the logger and handler's level.
Container for colormaps that are known to Matplotlib by name.
Experimental
While we expect the API to be final, we formally mark it as experimental for 3.5 because we want to keep the option to still adapt the API for 3.6 should the need arise.
The universal registry instance is matplotlib.colormaps
. There should be no need for users to instantiate ColormapRegistry
themselves.
Read access uses a dict-like interface mapping names to Colormap
s:
import matplotlib as mpl cmap = mpl.colormaps['viridis']
Returned Colormap
s are copies, so that their modification does not change the global definition of the colormap.
Additional colormaps can be added via ColormapRegistry.register
:
mpl.colormaps.register(my_colormap)
Return the string path of the cache directory.
The procedure used to find the directory is the same as for _get_config_dir, except using $XDG_CACHE_HOME
/$HOME/.cache
instead.
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/matplotlib_configuration_api.html