Matplotlib Startup¶
We’ll begin documenting the configuration for matplotlib
and how the
built-in matplotlib.pyplot
API can be utilized for
IPython’s configuration.
In [1]: import matplotlib as mpl
In [2]: mpl.pyplot.rc
Out[2]: <function matplotlib.pyplot.rc(group, **kwargs)>
In [3]: # pdoc mpl.pyplot.rc
Where the %pdoc
magic produces:
- Class docstring:
Set the current rc params. group is the grouping for the rc, e.g., for
lines.linewidth
the group islines
, foraxes.facecolor
, the group isaxes
, 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 kwargsThis enables you to easily switch between several configurations. Use
matplotlib.style.use('default')
orrcdefaults()
to restore the default rc params after changes.- Call docstring:
Call self as a function.
Well that’s neat!
So fun fact: If you write a print()
statement in a code-block
it’ll generate error as no code is saved and you essentially created an
empty block.
But running %pdoc
will actually output a classes docstring to your terminal
in the middle of a sphinx build!