How do I set the figure title and axes labels font size?

In matplotlib, you can set the font size of the figure title and axes labels using the pyplot module. Here is an example code snippet that demonstrates how to set the font size for the title and x and y axes labels:

import matplotlib.pyplot as plt

# create a figure and axes
fig, ax = plt.subplots()

# set the font size for the title
plt.title("My Figure Title", fontsize=14)

# set the font size for the x and y axes labels
ax.set_xlabel("X Label", fontsize=12)
ax.set_ylabel("Y Label", fontsize=12)

# plot some data
ax.plot([1, 2, 3], [4, 5, 6])

# show the plot
plt.show()

You can adjust the font size as per your requirement.

Watch a course Python - The Practical Guide

Alternatively, you can use the rcParams method to set the font size of the title and labels globally.

import matplotlib as mpl
mpl.rcParams['axes.labelsize'] = 14
mpl.rcParams['axes.titlesize'] = 16

This change will apply to all subsequent plots created using matplotlib in the current session.