Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib text underline

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.

like image 526
user2958481 Avatar asked Oct 11 '25 19:10

user2958481


1 Answers

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.

like image 94
closlas Avatar answered Oct 14 '25 12:10

closlas