How Do You Add Title to Subplots in Matplotlib (With Examples)

In Matplotlib, you can add titles to subplots using the set_title() method. This method takes in a string that contains the title text as its only parameter. An example of how to use this method would be: ax.set_title(“My Title”) where ax is the name of the axis instance. You can also adjust the font size, font weight, and font style of the title by passing additional parameters to the set_title() method.


You can use the following basic syntax to add a title to a subplot in Matplotlib:

ax[0, 1].set_title('Subplot Title')

The following examples shows how to use this syntax in practice.

Example 1: Add Titles to Subplots in Matplotlib

The following code shows how to create a grid of 2×2 subplots and specify the title of each subplot:

import matplotlib.pyplot as plt

#define subplots
fig, ax = plt.subplots(2, 2)

#define subplot titles
ax[0, 0].set_title('First Subplot')
ax[0, 1].set_title('Second Subplot')
ax[1, 0].set_title('Third Subplot')
ax[1, 1].set_title('Fourth Subplot')

Notice that each subplot has a unique title.

Example 2: Add Customized Titles to Subplots in Matplotlib

We can use the following arguments to customize the titles of the subplots:

  • fontsize: The font size of the title
  • loc: The location of the title (“left”, “center”, “right”)
  • x, y: The (x, y) coordinates of the title
  • color: The font color of the title
  • fontweight: The font weight of the title

The following code shows how to use these arguments in practice:

import matplotlib.pyplot as plt

#define subplots
fig, ax = plt.subplots(2, 2)

#define subplot titles
ax[0, 0].set_title('First Subplot', fontsize=18, loc='left')
ax[0, 1].set_title('Second Subplot', x=.75, y=.9)
ax[1, 0].set_title('Third Subplot', color='red')
ax[1, 1].set_title('Fourth Subplot', fontweight='bold')

Using these various arguments, you can customize the subplot titles to look however you’d like.

The following tutorials explain how to perform other common operations in Matplotlib:

How to Adjust Title Position in Matplotlib

x