Change the base font size in Matplotlib

Python

Matplotlib

Change base font size

Luc B.

Python

Matplotlib

Font

For projects with multiple visualizations, it is important that plots are visually consistent with each other. To address this, Matplotlib has a function to globally modify plot styles named matplotlib.rc(). Style changes made with this function will apply to all plots in a script.

Code Example

To globally change base the font size in Matplotlib, tweak the matplotlibrc using the matplotlib.rc() function.

import matplotlib.pyplot as plt
import matplotlib

# Adjust the font size here
matplotlib.rc('font', size='30')

plt.title("My Title")
plt.xlabel("My 'X' Label")
plt.ylabel("My 'Y' Label")

plt.show()

png

This changes Matplotlib's base font size, meaning Matplotlib will adjust larger text elements to be in proportion with the base size.