How to use matplotlib.pyplot.title() function In Python
The title() method in matplotlib module is used to specify title of the visualization depicted and displays the title using various attributes.
Syntax:
matplotlib.pyplot.title(label, fontdict=None, loc=’center’, pad=None, **kwargs)
Example 1:
In this example, we will look at how to give a title, Matplotlib provides a function title() which is used to give a title for the plots.
Python3
#import matplotlib import matplotlib.pyplot as plt # Points to mark plt.plot([ 1 , 2 , 3 , 4 , 5 ], [ 1 , 4 , 6 , 14 , 25 ]) # X label plt.xlabel( 'X-axis' ) # Y label plt.ylabel( 'Y-axis' ) # Title plt.title( 'Title' ) |
Output:
By default, TitleTitle is placed in the center; it is pretty simple to change them.
Example 2:
In this example, we have placedTitleTitle to the right of the plot using matplotlib.pyplot.title() function by initializing the argument as right.
Python3
#import matplotlib import matplotlib.pyplot as plt # Points to mark plt.plot([ 1 , 2 , 3 , 4 , 5 ], [ 1 , 4 , 6 , 14 , 25 ]) # X label plt.xlabel( 'X-axis' ) # Y label plt.ylabel( 'Y-axis' ) # Title plt.title( 'Title' , loc = 'right' ) |
Output:
Example 3:
In this example, we have placedTitleTitle to the left of the plot using matplotlib.pyplot.title() function by initializing the argument as left.
Python3
#import matplotlib import matplotlib.pyplot as plt # Points to mark plt.plot([ 1 , 2 , 3 , 4 , 5 ], [ 1 , 4 , 6 , 14 , 25 ]) # X label plt.xlabel( 'X-axis' ) # Y label plt.ylabel( 'Y-axis' ) # Title plt.title( 'Title' , loc = 'left' ) |
Output:
How to Adjust Title Position in Matplotlib?
In this article, you learn how to modify the Title position in matplotlib in Python.