matplotlib configuration

matplotlib

This is an object-orient plotting library.

A procedural interface is provided by the companion pylab module, which may be imported directly, e.g:

from pylab import *

or using ipython:

ipython -pylab

For the most part, direct use of the object-oriented library is encouraged when programming rather than working interactively. The exceptions are the pylab commands figure(), subplot(), show(), and savefig(), which can greatly simplify scripting.

Modules include:

matplotlib.axes
defines the Axes class. Most pylab commands are wrappers for Axes methods. The axes module is the highest level of OO access to the library.
matplotlib.figure
defines the Figure class.
matplotlib.artist
defines the Artist base class for all classes that draw things.
matplotlib.lines
defines the Line2D class for drawing lines and markers
:mod`matplotlib.patches`
defines classes for drawing polygons
matplotlib.text
defines the Text, TextWithDash, and Annotate classes
matplotlib.image
defines the AxesImage and FigureImage classes
matplotlib.collections
classes for efficient drawing of groups of lines or polygons
matplotlib.colors
classes for interpreting color specifications and for making colormaps
matplotlib.cm
colormaps and the ScalarMappable mixin class for providing color mapping functionality to other classes
matplotlib.ticker
classes for calculating tick mark locations and for formatting tick labels
matplotlib.backends
a subpackage with modules for various gui libraries and output formats

The base matplotlib namespace includes:

rcParams
a global dictionary of default configuration settings. It is initialized by code which may be overridded by a matplotlibrc file.
rc()
a function for setting groups of rcParams values
use()
a function for setting the matplotlib backend. If used, this function must be called immediately after importing matplotlib for the first time. In particular, it must be called before importing pylab (if pylab is imported).

matplotlib is written by John D. Hunter (jdh2358 at gmail.com) and a host of others.

matplotlib.rc(group, **kwargs)

Set the current rc params. Group is the grouping for the rc, eg. 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, eg. (xtick, ytick). kwargs is a dictionary attribute name/value pairs, eg:

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. Eg, 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 rcdefaults() to restore the default rc params after changes.

matplotlib.rcdefaults()
Restore the default rc params - the ones that were created at matplotlib load time.
matplotlib.use(arg)

IPython wrapper for matplotlib’s backend switcher.

In interactive use, we can not allow switching to a different interactive backend, since thread conflicts will most likely crash the python interpreter. This routine does a safety check first, and refuses to perform a dangerous switch. It still allows switching to non-interactive backends.

Table Of Contents

Previous topic

The Matplotlib API

Next topic

matplotlib afm

This Page

Quick search