Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bold text in matplotlib table

How to insert bold text in a cell of matplotlib table (pyplot table) ?

import matplotlib.pyplot as plt
plt.table(cellText=[['my_texte_bold', 'other cell'], ['cell1', 'cell2'])
like image 949
Clément v Avatar asked Aug 11 '26 15:08

Clément v


1 Answers

You can use tex code in matplotlib texts. In this way you can also mix different font properties

import matplotlib.pyplot as plt
t=plt.table(cellText=[['my_texte_$\\bf{bold}$', 'other cell'], ['cell1', 'cell2']])
t.scale(1,7)
plt.axis('off')

giving you

enter image description here

Note: You might face the problem that whitespaces are lost in the bold region. In this case use strBold.replace(' ','\\ '). This puts a '\\' in front of every whitespace.

See also: https://stackoverflow.com/a/61538854/7128154 for more options based on an plt.text example

like image 176
Markus Dutschke Avatar answered Aug 13 '26 06:08

Markus Dutschke