4

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.

1
  • I think the dash is clipped away, try with clip_on=False. Commented Sep 2, 2017 at 2:38

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.