Set fonts in matplotlib graphs equal to tex document
There is matplotlib2tikz
, which creates a TikZ/pgfplots file that can be \input
in your document. I don't know how well it works, having never used matplotlib
, but I have used matlab2tikz
from the same author, and that works well. Also, I do not know if matplotlib2tikz
supports all the different kinds of plots that matplotlib
can create – in the Matlab case there are some limitations I believe.
Edit: For reference, here is a brief explanation of installation and use.
Having downloaded the files from github, navigate to the folder in a command line, and run python setup.py install
to install matplotlib2tikz
.
In your Python script add from matplotlib2tikz import matplotlib2tikz
, and add matplotlib2tikz('filename.tex')
after your plot, e.g.
from numpy import arange
from matplotlib2tikz import matplotlib2tikz
import matplotlib.pyplot as plt
x = arange(0,10,0.5)
plt.plot(x,x**2)
plt.title("A lovely plot")
plt.ylabel("$y=x^2$")
matplotlib2tikz('test.tex')
You can also specify the width and height of the plot in the Python script, as mentioned in the readme of matplotlib2tikz
.
Matplotlib now includes a PGF backend as of the 1.2 release. See this GitHub issue.