3

I am trying to add underline to one of the character in plt.text.

plt.text(.5,.5,r'\underline{O}H')

This does not seem to work, I tried to use \overline{O}, which works just fine. I also tried plt.rc('text',usetex=True) even this does not seem to work.

Please help me get underline for a text in matplitlib.

user2958481
  • 587
  • 2
  • 8
  • 20

1 Answers1

5

I imagine you have had a look at this question (Underlining Text in Python/Matplotlib) If not this would be my first suggestion.

Secondly, I have tried and successfully underlined text. Here is the snippet of code that worked for me:

import numpy as np
import matplotlib.pyplot as plt
plt.rc('text', usetex=True)

x = np.arange(0, 2*np.pi, 0.1)
plt.plot(x, np.sin(x))
plt.text(x[len(x)//2], .5, r'$\underline{sin(x)}$')
plt.show()

And this is the result

Finally, if none of the above have worked, I would suggest looking at your python distribution. Rendering text with LaTeX requires a working LaTeX installation as explained in the matplotlib documentation http://matplotlib.org/users/usetex.html, so this could be one potential issue you are having.

Additionally I would suggest that you add a bit more info on your system & a working snippet of code. This would help narrow down the suggestions/solutions to your problem.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
closlas
  • 136
  • 8