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}$')
Share:
24,837

Related videos on Youtube

Rohit
Author by

Rohit

An Astrophysicist who's getting away from IRAF & IDL and into Python

Updated on July 09, 2022

Comments

  • Rohit
    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}$')
    

    enter image description here

    • fjarri
      fjarri over 10 years
      \rm works for me. Just to be sure, are you escaping the backslash?
    • tacaswell
      tacaswell over 10 years
      Are you using p3k? Escaping is going to get nasty. You might need to do '\\rm{eff}'.
    • Werner
      Werner over 10 years
      I would suggest using $T_{\mathrm{eff}}$, unless T is used in text mode within your document.
    • Rohit
      Rohit over 10 years
      \mathrm did the job for me. No, I am using Python 2.7. Thanks a lot all of you!
  • sodd
    sodd almost 10 years
    In LaTeX2e the \rm command is deprecated, and should not be used.
  • nijoakim
    nijoakim over 7 years
    'Primary T$_\mathrm{eff}$' also works if you are worried about deprecation.