Change the font size on a matplotlib plot

Last Updated On Thursday 28th Oct 2021

Introduction

Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy.Matplotlib is one of the most widely used data visualization libraries in Python.

matplotlib font size

There are a few ways you can go about changing the size of fonts in Matplotlib.

This sets the font of all items to the font specified by the kwargs object, font.

	font = {'family' : 'normal',
        'weight' : 'bold',
        'size'   : 22}

matplotlib.rc('font', **font)
	

You Can use the rcParams update method

	class matplotlib.RcParams(*args, **kwargs)
	

A dictionary object including validation.Validating functions are defined and associated with rc parameters in matplotlib.rcsetup.

	matplotlib.rcParams.update({'font.size': 22})
	
	import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})
	

matplotlib text size

	import matplotlib.pyplot as plt

SMALL_SIZE = 8
MEDIUM_SIZE = 10
BIGGER_SIZE = 12

plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title
	
	import matplotlib

SMALL_SIZE = 8
matplotlib.rc('font', size=SMALL_SIZE)
matplotlib.rc('axes', titlesize=SMALL_SIZE)
...
	

matplotlib axis font size

References