I couldn't find another thread or documentation on this topic - has anyone ever been successful underlining in pythons matplotlib package? The syntax I am using is something like this for all the other attributes:
plt.text(0.05, 0.90, 'Parameters: ', fontsize=12)
However, I can't figure out how to underline this text short of actually coding a line into the file.
Thoughts?
To Underline Text In Python, the Unicode character "\u0332" , acts as an underline on the character that precedes it in a string. So, if you put any string after this Unicode, the text will be printed underlined in Python.
The matplotlib. pyplot. text() function is used to add text inside the plot. The syntax adds text at an arbitrary location of the axes.
Matplotlib can use LaTeX to handle all text, see this page of the documnetation for more information. The command for underlining text in LaTeX is simply \underline
. From the docstring of one of the example scripts:
You can use TeX to render all of your matplotlib text if the
rc
parameter text.usetex is set. This works currently on theagg
andps
backends, and requires that you have tex and the other dependencies described at http://matplotlib.sf.net/matplotlib.texmanager.html properly installed on your system. The first time you run a script you will see a lot of output from tex and associated tools. The next time, the run may be silent, as a lot of the information is cached in ~/.tex.cache
So as a simple example we can do
import matplotlib.pyplot as plt
from matplotlib import rc
rc('text', usetex=True)
plt.sunplot(111)
plt.text(0.05, 0.90, r'\underline{Parameters}: ', fontsize=12)
to get underlined text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With