Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)    
like image 900
Bruce Avatar asked Oct 21 '10 09:10

Bruce


People also ask

How do you subscript axis labels in Excel?

Right-click on the highlighted text and go to “Format axis title”. 5. Select the “Font” tab. To make characters into superscripts or subscripts, check the appropriate box in the lower left portion of the dialogue box.

How do you write a subscript in Matplotlib legend?

The Matplotlib also provides a way to write subscripts or superscripts using the dollar sign. To make subscripts, you have to write the expression inside the dollar sign using the _ and ^ symbols. If you use the _ symbol, the superscript will be under the character.

How do you subscript in SPSS?

Edit one of the resulting labels and place your cursor where you want a subscript or superscript. While holding down the ALT-key on your keyboard, type the UNICODE associated with the desired superscript or subscript. For example, type 0179 while holding the ALT-key to get a superscript 3.


2 Answers

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

like image 200
Jouni K. Seppänen Avatar answered Oct 11 '22 15:10

Jouni K. Seppänen


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) 
like image 27
Andrew Walker Avatar answered Oct 11 '22 17:10

Andrew Walker