remove italics in latex subscript in matplotlib
24,837
I have encountered this problem many times and it can be solved with this trick
plt.xlabel(r'Primary T$_{\rm eff}$')
Related videos on Youtube
Author by
Rohit
An Astrophysicist who's getting away from IRAF & IDL and into Python
Updated on July 09, 2022Comments
-
Rohit almost 2 years
I would like to remove the italics font that appears when I use subscripts in labels. For example, the "Teff" in the x-label has "eff" in italics. I would like latex not render it in such a way. Generally, in latex this can be achieved with the \rm{} command. However, that does not work in matplotlib. Please help.
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = x plt.plot(x,y,'ro') plt.xlabel('Primary T$_{eff}$')
-
fjarri over 10 years
\rm
works for me. Just to be sure, are you escaping the backslash? -
tacaswell over 10 yearsAre you using p3k? Escaping is going to get nasty. You might need to do
'\\rm{eff}'
. -
Werner over 10 yearsI would suggest using
$T_{\mathrm{eff}}$
, unlessT
is used in text mode within your document. -
Rohit over 10 years\mathrm did the job for me. No, I am using Python 2.7. Thanks a lot all of you!
-
-
sodd almost 10 yearsIn LaTeX2e the
\rm
command is deprecated, and should not be used. -
nijoakim over 7 years'Primary T$_\mathrm{eff}$' also works if you are worried about deprecation.