Matplotlib.pyplot.suptitle() function in Python (original) (raw)

Last Updated : 28 Jul, 2020

Matplotlib is a library in Python and it is a mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface.

matplotlib.pyplot.suptitle() Function

The suptitle() function in pyplot module of the matplotlib library is used to add a title to the figure.

Syntax: matplotlib.pyplot.suptitle(t, **kwargs)

Parameters: This function will have following parameters:

Returns: The Text instance of the title.

Below examples illustrate the matplotlib.pyplot.suptitle() function in matplotlib.pyplot:

Example 1: Adding a title to the graph with font size 12.

Python3 `

importing matplotlib.pyplot module

import matplotlib.pyplot as plt

values of x and y axes

x = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60] y = [1, 4, 3, 2, 7, 6, 9, 8, 10, 5]

plotting the graph

plt.plot(x, y)

labelling axes

plt.xlabel('x') plt.ylabel('y')

adding title to the graph

with font size 12

plt.suptitle('This is the figure title', fontsize = 12)

show the plot

plt.show()

`

Output :

Example 2: Adding title to the graph with left horizontal alignment and font size 12.

Python3 `

importing matplotlib.pyplot module

import matplotlib.pyplot as plt

values of x and y axes

x = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]

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

plotting the graph

plt.plot(x, y)

labelling axes

plt.xlabel('x') plt.ylabel('y')

Adding title to the graph

with left horizontal alignment

and font size 12.

plt.suptitle('This is the figure title', ha = 'left', fontsize = 12)

`

Output:

Example 3: Adding title to the graph with extra bold font weight and large font size.

Python3 `

importing matplotlib.pyplot module

import matplotlib.pyplot as plt

values of x and y axes

x = [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]

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

plotting the graph

plt.plot(x, y)

labelling axes

plt.xlabel('x') plt.ylabel('y')

Adding title to the graph

with extra bold font weight

and large font size.

plt.suptitle('This is the figure title', fontsize = 'xx-large', weight = 'extra bold')

`

Output: