How do I write text in subscript in the axis labels and the legend?

Question:

I have the following axis labels and legend.

plt.ylabel("ratio_2")
plt.xlabel("n_1")
plt.legend(('alpha_1','alpha_2' ), loc = 'best',shadow = True)   
Asked By: Bruce

||

Answers:

The easiest way I know is to enable TeX mode for matplotlib,

from http://www.scipy.org/Cookbook/Matplotlib/UsingTex:

from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)
Answered By: Andrew Walker

Put dollar signs around the formula: plt.xlabel("$n_1$")

Answered By: Jouni K. Seppänen
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.