How to increase Text size in ConfusionMatrix

Viewed 2025

I Have a CM and want the text to be bold. So all the numbers and the labels as well. Heres the code:

array = np.array([[1003, 32], [30, 51]])
labels = np.array(["Label 1", "Label 2"])
disp = ConfusionMatrixDisplay(confusion_matrix=array, display_labels=labels)

disp = disp.plot(include_values=True, cmap="Reds", ax=None, xticks_rotation="horizontal")
plt.show()

Is there any easy way to change it to a bold style?

1 Answers

This kind of plot relies on the library matplotlib that I guess you imported as

import matplotlib.pyplot as plt

I would suggest you to set the params for the font before your plot.

font = {'family' : 'normal',
    'weight' : 'bold',
    'size'   : 22}
plt.rc('font', **font)

If interested in more detail take a look at that question How to change the font size on a matplotlib plot

Related