Matplotlib LaTeX: Inconsistent Behaviour with Greek Letters (Specifically \rho)

Viewed 11733

I'm trying to add some axis-labels to a graph which contains the Greek letter 'rho'. To do this I want to use the LaTeX capability of Matplotlib but it seems to have a problem with the \rho symbol.

Here is a minimal example:

import matplotlib.pyplot as plt
from matplotlib import rc,rcParams

rc('text',usetex=True)
rcParams.update({'font.size': 16})

plt.plot([0,1,2,3,4],[0,1,4,9,16])
plt.xlabel('\rho A_i') # works if \rho is replaced with, for example, \sigma
plt.ylabel('Something else')
plt.show()

Upon running the first time I get a bunch of LaTeX errors and a blank figure window, running again shows the graph but the xlabel reads 'ho Ai ' where the i is subscript as expected.

The weird thing is if I replace \rho with something else, say, \sigma it shows up correctly. Can anybody tell me why it is not happy with my code example and how to fix it?

Thanks.

P.s. I tried putting the expression in $..$ but that changed nothing.

2 Answers
Related