How to Adjust Title Position in Matplotlib? - GeeksforGeeks

28 Nov, 2021
In this article, you learn how to modify the Title position in matplotlib 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 matplotlibimport matplotlib.pyplot as plt  # Points to markplt.plot([1, 2, 3, 4, 5], [1, 4, 6, 14, 25])  # X labelplt.xlabel('X-axis')  # Y labelplt.ylabel('Y-axis')  # Titleplt.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 matplotlibimport matplotlib.pyplot as plt  # Points to markplt.plot([1, 2, 3, 4, 5], [1, 4, 6, 14, 25])  # X labelplt.xlabel('X-axis')  # Y labelplt.ylabel('Y-axis')  # Titleplt.title('Title', loc='right')
Output:
right
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 matplotlibimport matplotlib.pyplot as plt  # Points to markplt.plot([1, 2, 3, 4, 5], [1, 4, 6, 14, 25])  # X labelplt.xlabel('X-axis')  # Y labelplt.ylabel('Y-axis')  # Titleplt.title('Title', loc='left')
Output:
In this method, we will place title inside the plot. Instead of giving the location in the “loc” parameter, we will give the exact location where it should be placed by using X and Y coordinates. 
Syntax:
 matplotlib.pyplot.title('Title', x=value, y=value)
Example:
In this example, we will be assigning the value of the x and y at the position where the title is to be placed in the python programming language.
Python3
#import matplotlibimport matplotlib.pyplot as plt  # Points to markplt.plot([1, 2, 3, 4, 5], [1, 4, 6, 14, 25])  # X labelplt.xlabel('X-axis')  # Y labelplt.ylabel('Y-axis')  # Titleplt.title('Title', x=0.4, y=0.8)
Output:
In this method, we will be using the pad argument of the title() function to change the title location in the given plot in the python programming language.
Syntax:
matplotlib.pyplot.title('Title', pad=value)
Example:
In this example, We will elevateTitleTitle by using the “pad” parameter. The offset of the Title from the top of the axes, in points. The default value is none.
Python3
#import matplotlibimport matplotlib.pyplot as plt  # Points to markplt.plot([1, 2, 3, 4, 5], [1, 4, 6, 14, 25])  # X labelplt.xlabel('X-axis')  # Y labelplt.ylabel('Y-axis')  # Title with padplt.title('Title', pad=50)
Output:
Picked
Python-matplotlib
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python OOPs Concepts
How to Install PIP on Windows ?
Bar Plot in Matplotlib
Defaultdict in Python
Python Classes and Objects
Deque in Python
Check if element exists in list in Python
How to drop one or multiple columns in Pandas Dataframe
Python - Ways to remove duplicates from list
Class method vs Static method in Python