Set the plot title in Matplotlib

Python

Matplotlib

Axes

Set title

Luc B.

Python

Matplotlib

The title is an important component of any Matplotlib plot, as it sets the context for the visualization and adds intrigue.

Code Example

Use the plt.title() function to set the plot title.

import matplotlib.pyplot as plt

# Set the title here
plt.title('My Plot Title')

plt.show()

png

More Examples

Object Oriented Interface

Matplotlib's object oriented interface includes the Axes.set_title() function to set the title.

ax = plt.axes()

# Set the title here
ax.set_title('My Plot Title')

plt.show()

png