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.title('title',**csfont)plt.xlabel('xlabel', **hfont)plt.show()
You can also use rcParams
to change the font family globally.
import matplotlib.pyplot as plt plt.rcParams["font.family"] = "cursive" # This will change to your computer's default cursive font
The list of matplotlib's font family arguments is here.
I prefer to employ:
from matplotlib import rc#rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})rc('font',**{'family':'serif','serif':['Times']})rc('text', usetex=True)