Matplotlib and LaTeX

General considerations

Matplotlib can be extremely useful for plotting, though it requires a little work in order to make the output be publication quality. Primarily, the default figure size does not conform to the golden mean. This is easy enough to fix by editing the matplotlibrc.py file (or changing it on the fly with calls to matplotlib.pyplot.rc). To get optimal results, it's good to make the figure size fit into a LaTeX document without resizing (this is because we don't want the fonts to be so tiny as to be unreadable). The long explanation on how to do this is here.

I have determined reasonable sizes and axes parameters to use for some different document classes and put them in a file that I keep in my $PYTHONPATH. For example, if I am going to make a figure for Physical Review Letters, I would do something like this (assuming you import matplotlib.pyplot as plt):

 plt.rcParams.update(mplparams.aps['params'])
 plt.figure()
 plt.axes(mplparams.aps['axes'])
 # Other commands follow

What's left

What I don't have a good solution for yet is getting all the tick labels to match the other fonts. For now, using the serif font is good enough, but for consistency, hopefully I can figure out the right way to do this later.

Similar Projects

2011-04-16: I was informed of a similar project, mplrc. Since I don't maintain the code here much, you might be better off checking that out.

Last updated 16 April 2011