I want to create labels to my plots with the latex computer modern font. However, the only way to persuade matplotlib to use the latex font is by inserting something like:
The default Latex font is known as Computer Modern
:
from matplotlib import rc
import matplotlib.pylab as plt
rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
rc('text', usetex=True)
x = plt.linspace(0,5)
plt.plot(x,plt.sin(x))
plt.ylabel(r"This is $\sin(x)$", size=20)
plt.show()
I am using matplotlib 1.3.1 on Mac OSX, add the following lines in matplotlibrc
works for me
text.usetex : True
font.family : serif
font.serif : cm
Using =
leads to a UserWarning: Illegal line
The marked answer can be enabled by default by changing a few lines in the matplotlibrc
file:
text.usetex = True
font.family = serif
font.serif = cm