Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlining Text in Python/Matplotlib

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?

like image 400
nodapic Avatar asked May 23 '12 20:05

nodapic


People also ask

How do I underline text in Python?

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.

How do I show text in Matplotlib?

The matplotlib. pyplot. text() function is used to add text inside the plot. The syntax adds text at an arbitrary location of the axes.


1 Answers

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 the agg and ps 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.

like image 99
Chris Avatar answered Oct 13 '22 00:10

Chris