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”.
</>
Copy
import matplotlib.pyplot as plt
plt.title('Sample Title')
Example
In this example, we will draw a plot, and set its title to “Sample Title”.
example.py
</>
Copy
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')
plt.show()
Output
Conclusion
Concluding this Matplotlib Tutorial, we learned how to set a title for the plot figure using Matplotlib library in Python.