Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to do subscripts/superscripts in Matplotlib without TeX?

I am finding that TeX messes with my fonts, the alignment of my subplot yaxis labels, etc and I feel like there must be an easier way to get subcripts and superscripts in plot labels. Help!

like image 706
Arnold Avatar asked Feb 21 '14 18:02

Arnold


People also ask

How do I type a subscript in Matplotlib?

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.


1 Answers

Just use \mathregular{whatever} in your expression.

For example:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.text(0.2, 0.7, 'No mathtex')
ax.text(0.2, 0.5, 'This superscript $is^{in}$ italics')
ax.text(0.2, 0.3, 'While this $\mathregular{is^{really}}$ the same font')
plt.show()

enter image description here

See http://matplotlib.org/users/mathtext.html for more information.

like image 68
Joe Kington Avatar answered Oct 17 '22 19:10

Joe Kington