Aldahunter
Aldahunter

Reputation: 658

How to put 'underbar' below a letter (underscored characters) in matplotlib?

Unfortunately due to a problem with windows I cannot render any of my matplotlib text with LaTeX. So basically I need away already in matplotlib's text handling to place a line underneath a letter.

So far the closest I have is ax.text(x,y,z, r'$\mathbf{\underbar r}$'), but this just produces _r. So if there is a way to get this bar under the 'r' that would be amazing. Thanks in advance!

P.S. I have already tried ax.text(x,y,z, r'$\underline{\mathbf{r}}$') but this doesn't seem to work, :,(

Edit

Just realized that you can 'cheat' matplotlib :D by placing text in the exact same position with just an \underbar, which makes it appear under the letter. i.e. ax.text(x,y,z, r'$\mathbf{r}$') followed by ax.text(x,y,z, r'$\mathbf{\underbar}$')

But a quicker way would still be appreciated, thanks!

Upvotes: 2

Views: 2606

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339220

You could use some negative spacing between the underbar and your character. In this case it seems that tripling the \! works well:

ax.text(2,7, r'$\mathbf{\underbar \!\!\! r }$')

enter image description here

Upvotes: 3

Related Questions