How do I change the font type of the text in a Matplotlib table?

Viewed 2373

I have a sample table made in matplotlib below:

import numpy as np
import matplotlib.pyplot as plt

collabel=("col 1", "col 2", "col 3")
new_data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

the_table = plt.table(cellText=new_data,colLabels=collabel,loc='center')
plt.axis("off")

plt.show()

I would just simply like to change the font type of the text shown in the tables (i.e. Arial, Courier, etc). I couldn't find a font property in the table() method, should I be trying to grab text items within the table?

2 Answers

You can set the font family in plt.rcParams before you plot the table:

plt.rcParams['font.family'] = 'Serif'
the_table = plt.table(cellText=new_data, colLabels=collabel, loc='center')
Related