Matplotlib – Set Title for Plot

To set title for plot in matplotlib, call title() function on the matplotlib.pyplot object and pass required title name as argument for the title() function.

The following code snippet sets the title of the plot to “Sample Title”.

import matplotlib.pyplot as plt
plt.title('Sample Title')


In this example, we will draw a plot, and set its title to “Sample Title”.

import matplotlib.pyplot as plt

x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
y = [5, 7, 8, 1, 4, 9, 6, 3, 5, 2, 1, 8]

plt.plot(x, y)

#set title for plot
plt.title('Sample Title')


Set Title for Plot in Matplotlib
“Sample Title” set as title for the plot


Concluding this Matplotlib Tutorial, we learned how to set a title for the plot figure using Matplotlib library in Python.