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)   
1
17
10/21/2010 9:03:51 AM

Accepted Answer

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

27
10/28/2010 2:47:46 PM

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon