The matplotlibrc file contains many useful parameters for tweaking your setup to your liking, and it’s worth at least skimming through to get an idea of what it contains. Editing the file makes more permanent changes, while using the pylab rcParams dictionary or rc() and rcdefaults() functions lets you make and revert changes on the fly.
View the rc parameters by using
import pylab as p
print p.rcParams
Examples ensue.
Where is matplotlibrc?
On my machine (Ubuntu 7.10) it’s in /usr/lib/python2.5/site-packages/matplotlib/mpl-data/matplotlibrc. If I wanted to customize it, I could put a copy in ~/.matplotlib/matplotlibrc. If you’re on Windows, you can put a copy in C:\Documents and Settings\yourname\.matplotlib
Editing this file makes changes that are in effect every time you use matplotlib.
To make temporary changes, use the pylab.rc function or set values in the rcParams dictionary. I’ll describe both ways below.
An example
For example, I want to make a series of plots for a manuscript. The default font size is a little too small for these plots, and tweaking the font size for every one of the plots would be tedious. Let’s see what my rc options are.
import pylab as p
p.rcParams
Among a large number of options, I see some that will be of use:
...
...
'axes.labelsize': 12.0,
...
'xtick.labelsize': 12.0,
...
'ytick.labelsize': 12,0,
...
Two ways to change settings
It’s personal preference which one you use. Either way, you only have to do this once. From then on, all plots will use these new parameters, until you reset the parameters using rcdefaults()
Using rcParams, I could set the properties like this:
rcParams['axes.labelsize'] = 16.0
p.rcParams['xtick.labelsize'] = 16.0
p.rcParams['ytick.labelsize'] = 16.0
Alternatively, I could use rc:
p.rc(('xtick','ytick','axes'), labelsize=16.0)
Now, plot!
p.plot([1,2,3])
p.xlabel('x axis')
p.ylabel('y axis')
p.show()
Here’s the new figure. Any other figure I make will have the same text size.

Until, that is, I reset to the defaults:
p.rcdefaults()
The result is this:

0 Responses to “Adjust settings for matplotlib using rc and matplotlibrc”