How to change fonts in matplotlib (python)?

How to change fonts in matplotlib (python)?

Say you want Comic Sans for the title and Helvetica for the x label.

csfont = {fontname:Comic Sans MS}
hfont = {fontname:Helvetica}

plt.xlabel(xlabel, **hfont)

You can also use rcParams to change the font family globally.

 import matplotlib.pyplot as plt
 plt.rcParams[] = cursive
 # This will change to your computers default cursive font

The list of matplotlibs font family arguments is here.

How to change fonts in matplotlib (python)?

I prefer to employ:

from matplotlib import rc
rc(text, usetex=True)

The last line ensures that tick labels are also in the correct font.

Leave a Reply

Your email address will not be published. Required fields are marked *