You are reading documentation for the unreleased version of Matplotlib. Try searching for the released version of this page instead?
Version 2.0.0b1.post7580.dev0+ge487118
matplotlib
Fork me on GitHub

This Page

The top level matplotlib module

matplotlib.use(arg, warn=True, force=False)

Set the matplotlib backend to one of the known backends.

The argument is case-insensitive. warn specifies whether a warning should be issued if a backend has already been set up. force is an experimental flag that tells matplotlib to attempt to initialize a new backend by reloading the backend module.

Note

This function must be called before importing pyplot for the first time; or, if you are not using pyplot, it must be called before importing matplotlib.backends. If warn is True, a warning is issued if you try and call this after pylab or pyplot have been loaded. In certain black magic use cases, e.g. pyplot.switch_backend(), we are doing the reloading necessary to make the backend switch work (in some cases, e.g., pure image backends) so one can set warn=False to suppress the warnings.

To find out which backend is currently set, see matplotlib.get_backend().

matplotlib.get_backend()

Return the name of the current backend.

matplotlib.rcParams

An instance of RcParams for handling default matplotlib values.

matplotlib.rc_context(rc=None, fname=None)

Return a context manager for managing rc settings.

This allows one to do:

with mpl.rc_context(fname='screen.rc'):
    plt.plot(x, a)
    with mpl.rc_context(fname='print.rc'):
        plt.plot(x, b)
    plt.plot(x, c)

The ‘a’ vs ‘x’ and ‘c’ vs ‘x’ plots would have settings from ‘screen.rc’, while the ‘b’ vs ‘x’ plot would have settings from ‘print.rc’.

A dictionary can also be passed to the context manager:

with mpl.rc_context(rc={'text.usetex': True}, fname='screen.rc'):
    plt.plot(x, a)

The ‘rc’ dictionary takes precedence over the settings loaded from ‘fname’. Passing a dictionary only is also valid. For example a common usage is:

with mpl.rc_context(rc={'interactive': False}):
    fig, ax = plt.subplots()
    ax.plot(range(3), range(3))
    fig.savefig('A.png', format='png')
    plt.close(fig)
matplotlib.rc(group, **kwargs)

Set the current rc params. 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 rc params 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 rc command 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 rc params after changes.

matplotlib.rc_file(fname)

Update rc params from file.

matplotlib.rcdefaults()

Restore the rc params from Matplotlib’s internal defaults.

See also

rc_file_defaults
Restore the rc params 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.
matplotlib.rc_file_defaults()

Restore the rc params from the original rc file loaded by Matplotlib.

class matplotlib.RcParams(*args, **kwargs)

A dictionary object including validation

validating functions are defined and associated with rc parameters in matplotlib.rcsetup

find_all(pattern)

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.

msg_depr = '%s is deprecated and replaced with %s; please use the latter.'
msg_depr_ignore = '%s is deprecated and ignored. Use %s instead.'
msg_depr_set = '%s is deprecated. Please remove it from your matplotlibrc and/or style files.'
msg_obsolete = '%s is obsolete. Please remove it from your matplotlibrc and/or style files.'
validate = {'backend': <function validate_backend>, 'backend_fallback': <function validate_bool>, 'backend.qt4': <matplotlib.rcsetup.ValidateInStrings object>, 'backend.qt5': <matplotlib.rcsetup.ValidateInStrings object>, 'webagg.port': <function validate_int>, 'webagg.address': <function validate_webagg_address>, 'webagg.open_in_browser': <function validate_bool>, 'webagg.port_retries': <function validate_int>, 'toolbar': <function validate_toolbar>, 'datapath': <function validate_path_exists>, 'interactive': <function validate_bool>, 'timezone': <function validate_string>, 'verbose.level': <matplotlib.rcsetup.ValidateInStrings object>, 'verbose.fileo': <function validate_string>, 'lines.linewidth': <function validate_float>, 'lines.linestyle': <function _validate_linestyle>, 'lines.color': <function validate_color>, 'lines.marker': <function validate_string>, 'lines.markeredgewidth': <function validate_float>, 'lines.markersize': <function validate_float>, 'lines.antialiased': <function validate_bool>, 'lines.dash_joinstyle': <matplotlib.rcsetup.ValidateInStrings object>, 'lines.solid_joinstyle': <matplotlib.rcsetup.ValidateInStrings object>, 'lines.dash_capstyle': <matplotlib.rcsetup.ValidateInStrings object>, 'lines.solid_capstyle': <matplotlib.rcsetup.ValidateInStrings object>, 'lines.dashed_pattern': <matplotlib.rcsetup.validate_nseq_float object>, 'lines.dashdot_pattern': <matplotlib.rcsetup.validate_nseq_float object>, 'lines.dotted_pattern': <matplotlib.rcsetup.validate_nseq_float object>, 'lines.scale_dashes': <function validate_bool>, 'markers.fillstyle': <matplotlib.rcsetup.ValidateInStrings object>, 'patch.linewidth': <function validate_float>, 'patch.edgecolor': <function validate_color>, 'patch.force_edgecolor': <function validate_bool>, 'patch.facecolor': <function validate_color>, 'patch.antialiased': <function validate_bool>, 'hatch.color': <function validate_color>, 'hatch.linewidth': <function validate_float>, 'hist.bins': <function validate_hist_bins>, 'boxplot.notch': <function validate_bool>, 'boxplot.vertical': <function validate_bool>, 'boxplot.whiskers': <function validate_whiskers>, 'boxplot.bootstrap': <function validate_int_or_None>, 'boxplot.patchartist': <function validate_bool>, 'boxplot.showmeans': <function validate_bool>, 'boxplot.showcaps': <function validate_bool>, 'boxplot.showbox': <function validate_bool>, 'boxplot.showfliers': <function validate_bool>, 'boxplot.meanline': <function validate_bool>, 'boxplot.flierprops.color': <function validate_color>, 'boxplot.flierprops.marker': <function validate_string>, 'boxplot.flierprops.markerfacecolor': <function validate_color_or_auto>, 'boxplot.flierprops.markeredgecolor': <function validate_color>, 'boxplot.flierprops.markersize': <function validate_float>, 'boxplot.flierprops.linestyle': <function _validate_linestyle>, 'boxplot.flierprops.linewidth': <function validate_float>, 'boxplot.boxprops.color': <function validate_color>, 'boxplot.boxprops.linewidth': <function validate_float>, 'boxplot.boxprops.linestyle': <function _validate_linestyle>, 'boxplot.whiskerprops.color': <function validate_color>, 'boxplot.whiskerprops.linewidth': <function validate_float>, 'boxplot.whiskerprops.linestyle': <function _validate_linestyle>, 'boxplot.capprops.color': <function validate_color>, 'boxplot.capprops.linewidth': <function validate_float>, 'boxplot.capprops.linestyle': <function _validate_linestyle>, 'boxplot.medianprops.color': <function validate_color>, 'boxplot.medianprops.linewidth': <function validate_float>, 'boxplot.medianprops.linestyle': <function _validate_linestyle>, 'boxplot.meanprops.color': <function validate_color>, 'boxplot.meanprops.marker': <function validate_string>, 'boxplot.meanprops.markerfacecolor': <function validate_color>, 'boxplot.meanprops.markeredgecolor': <function validate_color>, 'boxplot.meanprops.markersize': <function validate_float>, 'boxplot.meanprops.linestyle': <function _validate_linestyle>, 'boxplot.meanprops.linewidth': <function validate_float>, 'font.family': <function _listify_validator.<locals>.f>, 'font.style': <function validate_string>, 'font.variant': <function validate_string>, 'font.stretch': <function validate_string>, 'font.weight': <function validate_string>, 'font.size': <function validate_float>, 'font.serif': <function _listify_validator.<locals>.f>, 'font.sans-serif': <function _listify_validator.<locals>.f>, 'font.cursive': <function _listify_validator.<locals>.f>, 'font.fantasy': <function _listify_validator.<locals>.f>, 'font.monospace': <function _listify_validator.<locals>.f>, 'text.color': <function validate_color>, 'text.usetex': <function validate_bool>, 'text.latex.unicode': <function validate_bool>, 'text.latex.preamble': <function _listify_validator.<locals>.f>, 'text.latex.preview': <function validate_bool>, 'text.hinting': <function validate_hinting>, 'text.hinting_factor': <function validate_int>, 'text.antialiased': <function validate_bool>, 'mathtext.cal': <function validate_font_properties>, 'mathtext.rm': <function validate_font_properties>, 'mathtext.tt': <function validate_font_properties>, 'mathtext.it': <function validate_font_properties>, 'mathtext.bf': <function validate_font_properties>, 'mathtext.sf': <function validate_font_properties>, 'mathtext.fontset': <matplotlib.rcsetup.ValidateInStrings object>, 'mathtext.default': <matplotlib.rcsetup.ValidateInStrings object>, 'mathtext.fallback_to_cm': <function validate_bool>, 'image.aspect': <function validate_aspect>, 'image.interpolation': <function validate_string>, 'image.cmap': <function validate_string>, 'image.lut': <function validate_int>, 'image.origin': <function validate_string>, 'image.resample': <function validate_bool>, 'image.composite_image': <function validate_bool>, 'contour.negative_linestyle': <function _validate_linestyle>, 'contour.corner_mask': <function validate_bool>, 'errorbar.capsize': <function validate_float>, 'axes.axisbelow': <function validate_axisbelow>, 'axes.hold': <function deprecate_axes_hold>, 'axes.facecolor': <function validate_color>, 'axes.edgecolor': <function validate_color>, 'axes.linewidth': <function validate_float>, 'axes.spines.left': <function validate_bool>, 'axes.spines.right': <function validate_bool>, 'axes.spines.bottom': <function validate_bool>, 'axes.spines.top': <function validate_bool>, 'axes.titlesize': <function validate_fontsize>, 'axes.titleweight': <function validate_string>, 'axes.titlepad': <function validate_float>, 'axes.grid': <function validate_bool>, 'axes.grid.which': <matplotlib.rcsetup.ValidateInStrings object>, 'axes.grid.axis': <matplotlib.rcsetup.ValidateInStrings object>, 'axes.labelsize': <function validate_fontsize>, 'axes.labelpad': <function validate_float>, 'axes.labelweight': <function validate_string>, 'axes.labelcolor': <function validate_color>, 'axes.formatter.limits': <matplotlib.rcsetup.validate_nseq_int object>, 'axes.formatter.use_locale': <function validate_bool>, 'axes.formatter.use_mathtext': <function validate_bool>, 'axes.formatter.min_exponent': <function validate_int>, 'axes.formatter.useoffset': <function validate_bool>, 'axes.formatter.offset_threshold': <function validate_int>, 'axes.unicode_minus': <function validate_bool>, 'axes.prop_cycle': <function validate_cycler>, 'axes.autolimit_mode': <matplotlib.rcsetup.ValidateInStrings object>, 'axes.xmargin': <matplotlib.rcsetup.ValidateInterval object>, 'axes.ymargin': <matplotlib.rcsetup.ValidateInterval object>, 'polaraxes.grid': <function validate_bool>, 'axes3d.grid': <function validate_bool>, 'scatter.marker': <function validate_string>, 'date.autoformatter.year': <function validate_string>, 'date.autoformatter.month': <function validate_string>, 'date.autoformatter.day': <function validate_string>, 'date.autoformatter.hour': <function validate_string>, 'date.autoformatter.minute': <function validate_string>, 'date.autoformatter.second': <function validate_string>, 'date.autoformatter.microsecond': <function validate_string>, 'legend.fancybox': <function validate_bool>, 'legend.loc': <matplotlib.rcsetup.ValidateInStrings object>, 'legend.numpoints': <function validate_int>, 'legend.scatterpoints': <function validate_int>, 'legend.fontsize': <function validate_fontsize>, 'legend.markerscale': <function validate_float>, 'legend.shadow': <function validate_bool>, 'legend.frameon': <function validate_bool>, 'legend.framealpha': <function validate_float_or_None>, 'legend.borderpad': <function validate_float>, 'legend.labelspacing': <function validate_float>, 'legend.handlelength': <function validate_float>, 'legend.handleheight': <function validate_float>, 'legend.handletextpad': <function validate_float>, 'legend.borderaxespad': <function validate_float>, 'legend.columnspacing': <function validate_float>, 'legend.facecolor': <function validate_color_or_inherit>, 'legend.edgecolor': <function validate_color_or_inherit>, 'xtick.top': <function validate_bool>, 'xtick.bottom': <function validate_bool>, 'xtick.major.size': <function validate_float>, 'xtick.minor.size': <function validate_float>, 'xtick.major.width': <function validate_float>, 'xtick.minor.width': <function validate_float>, 'xtick.major.pad': <function validate_float>, 'xtick.minor.pad': <function validate_float>, 'xtick.color': <function validate_color>, 'xtick.minor.visible': <function validate_bool>, 'xtick.minor.top': <function validate_bool>, 'xtick.minor.bottom': <function validate_bool>, 'xtick.major.top': <function validate_bool>, 'xtick.major.bottom': <function validate_bool>, 'xtick.labelsize': <function validate_fontsize>, 'xtick.direction': <function validate_string>, 'xtick.alignment': <matplotlib.rcsetup.ValidateInStrings object>, 'ytick.left': <function validate_bool>, 'ytick.right': <function validate_bool>, 'ytick.major.size': <function validate_float>, 'ytick.minor.size': <function validate_float>, 'ytick.major.width': <function validate_float>, 'ytick.minor.width': <function validate_float>, 'ytick.major.pad': <function validate_float>, 'ytick.minor.pad': <function validate_float>, 'ytick.color': <function validate_color>, 'ytick.minor.visible': <function validate_bool>, 'ytick.minor.left': <function validate_bool>, 'ytick.minor.right': <function validate_bool>, 'ytick.major.left': <function validate_bool>, 'ytick.major.right': <function validate_bool>, 'ytick.labelsize': <function validate_fontsize>, 'ytick.direction': <function validate_string>, 'ytick.alignment': <matplotlib.rcsetup.ValidateInStrings object>, 'grid.color': <function validate_color>, 'grid.linestyle': <function _validate_linestyle>, 'grid.linewidth': <function validate_float>, 'grid.alpha': <function validate_float>, 'figure.titlesize': <function validate_fontsize>, 'figure.titleweight': <function validate_string>, 'figure.figsize': <matplotlib.rcsetup.validate_nseq_float object>, 'figure.dpi': <function validate_float>, 'figure.facecolor': <function validate_color>, 'figure.edgecolor': <function validate_color>, 'figure.frameon': <function validate_bool>, 'figure.autolayout': <function validate_bool>, 'figure.max_open_warning': <function validate_int>, 'figure.subplot.left': <matplotlib.rcsetup.ValidateInterval object>, 'figure.subplot.right': <matplotlib.rcsetup.ValidateInterval object>, 'figure.subplot.bottom': <matplotlib.rcsetup.ValidateInterval object>, 'figure.subplot.top': <matplotlib.rcsetup.ValidateInterval object>, 'figure.subplot.wspace': <matplotlib.rcsetup.ValidateInterval object>, 'figure.subplot.hspace': <matplotlib.rcsetup.ValidateInterval object>, 'savefig.dpi': <function validate_dpi>, 'savefig.facecolor': <function validate_color>, 'savefig.edgecolor': <function validate_color>, 'savefig.frameon': <function validate_bool>, 'savefig.orientation': <matplotlib.rcsetup.ValidateInStrings object>, 'savefig.jpeg_quality': <function validate_int>, 'savefig.format': <function update_savefig_format>, 'savefig.bbox': <function validate_bbox>, 'savefig.pad_inches': <function validate_float>, 'savefig.directory': <function validate_string>, 'savefig.transparent': <function validate_bool>, 'tk.window_focus': <function validate_bool>, 'ps.papersize': <matplotlib.rcsetup.ValidateInStrings object>, 'ps.useafm': <function validate_bool>, 'ps.usedistiller': <function validate_ps_distiller>, 'ps.distiller.res': <function validate_int>, 'ps.fonttype': <function validate_fonttype>, 'pdf.compression': <function validate_int>, 'pdf.inheritcolor': <function validate_bool>, 'pdf.use14corefonts': <function validate_bool>, 'pdf.fonttype': <function validate_fonttype>, 'pgf.debug': <function validate_bool>, 'pgf.texsystem': <matplotlib.rcsetup.ValidateInStrings object>, 'pgf.rcfonts': <function validate_bool>, 'pgf.preamble': <function _listify_validator.<locals>.f>, 'svg.image_inline': <function validate_bool>, 'svg.fonttype': <function validate_svg_fonttype>, 'svg.hashsalt': <function validate_string_or_None>, 'docstring.hardcopy': <function validate_bool>, 'path.simplify': <function validate_bool>, 'path.simplify_threshold': <matplotlib.rcsetup.ValidateInterval object>, 'path.snap': <function validate_bool>, 'path.sketch': <function validate_sketch>, 'path.effects': <function validate_any>, 'agg.path.chunksize': <function validate_int>, 'keymap.fullscreen': <function _listify_validator.<locals>.f>, 'keymap.home': <function _listify_validator.<locals>.f>, 'keymap.back': <function _listify_validator.<locals>.f>, 'keymap.forward': <function _listify_validator.<locals>.f>, 'keymap.pan': <function _listify_validator.<locals>.f>, 'keymap.zoom': <function _listify_validator.<locals>.f>, 'keymap.save': <function _listify_validator.<locals>.f>, 'keymap.quit': <function _listify_validator.<locals>.f>, 'keymap.quit_all': <function _listify_validator.<locals>.f>, 'keymap.grid': <function _listify_validator.<locals>.f>, 'keymap.grid_minor': <function _listify_validator.<locals>.f>, 'keymap.yscale': <function _listify_validator.<locals>.f>, 'keymap.xscale': <function _listify_validator.<locals>.f>, 'keymap.all_axes': <function _listify_validator.<locals>.f>, 'examples.directory': <function validate_string>, 'animation.html': <matplotlib.rcsetup.ValidateInStrings object>, 'animation.embed_limit': <function validate_float>, 'animation.writer': <matplotlib.rcsetup.ValidateInStrings object>, 'animation.codec': <function validate_string>, 'animation.bitrate': <function validate_int>, 'animation.frame_format': <matplotlib.rcsetup.ValidateInStrings object>, 'animation.html_args': <function _listify_validator.<locals>.f>, 'animation.ffmpeg_path': <function validate_animation_writer_path>, 'animation.ffmpeg_args': <function _listify_validator.<locals>.f>, 'animation.avconv_path': <function validate_animation_writer_path>, 'animation.avconv_args': <function _listify_validator.<locals>.f>, 'animation.convert_path': <function validate_animation_writer_path>, 'animation.convert_args': <function _listify_validator.<locals>.f>, '_internal.classic_mode': <function validate_bool>}
matplotlib.rc_params(fail_on_error=False)

Return a matplotlib.RcParams instance from the default matplotlib rc file.

matplotlib.rc_params_from_file(fname, fail_on_error=False, use_default_template=True)

Return matplotlib.RcParams from the contents of the given file.

Parameters:

fname : str

Name of file parsed for matplotlib settings.

fail_on_error : bool

If True, raise an error when the parser fails to convert a parameter.

use_default_template : bool

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.)

matplotlib.matplotlib_fname()

Get the location of the config file.

The file location is determined in the following order

  • $PWD/matplotlibrc

  • $MATPLOTLIBRC if it is a file (or a named pipe, which can be created e.g. by process substitution)

  • $MATPLOTLIBRC/matplotlibrc

  • $MPLCONFIGDIR/matplotlibrc

  • On Linux,

    • $XDG_CONFIG_HOME/matplotlib/matplotlibrc (if $XDG_CONFIG_HOME is defined)
    • or $HOME/.config/matplotlib/matplotlibrc (if $XDG_CONFIG_HOME is not defined)
  • On other platforms,

    • $HOME/.matplotlib/matplotlibrc if $HOME is defined.
  • Lastly, it looks in $MATPLOTLIBDATA/matplotlibrc for a system-defined copy.

matplotlib.interactive(b)

Set interactive mode to boolean b.

If b is True, then draw after every plotting command, e.g., after xlabel

matplotlib.is_interactive()

Return true if plot mode is interactive