Set Titles for Each Subplot and Overall Title in Matplotlib

When I started working with Python Matplotlib, I often created multiple subplots to compare different datasets side by side.

But one issue I faced was making my charts clear and readable. Each subplot needed its own title, and sometimes I also wanted one big title for the entire figure.

If you’ve faced the same challenge, don’t worry. In this tutorial, I’ll show you how to set titles for each subplot and also add an overall title in Matplotlib.

Set Titles for Each Subplot in Python Matplotlib

When working with multiple subplots, adding titles to each one helps your audience quickly understand what each chart represents.

Here are two easy methods I use to set subplot titles.

Method 1 – Use Axes.set_title() in Python

The most common way to add a title to a subplot is by using the set_title() method on the Axes object. This method is simple, direct, and works perfectly when you’re creating subplots using plt.subplots().

import matplotlib.pyplot as plt
import numpy as np

# Generate sample data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))

# Plot data
ax1.plot(x, y1, color="blue")
ax2.plot(x, y2, color="green")

# Add titles to each subplot
ax1.set_title("Sine Wave")
ax2.set_title("Cosine Wave")

# Show the plot
plt.show()

I have executed the above example code and added the screenshot below.

Titles for Each Subplot and Overall Title in Matplotlib

In this example, each subplot gets its own title using set_title(). This is the method I use most often when I want quick and clear titles.

Method 2 – Use plt.title() with plt.subplot() in Python

Another way to set subplot titles is by using plt.title() after selecting a specific subplot with plt.subplot().

This approach is especially useful if you’re creating subplots without explicitly using plt.subplots().

import matplotlib.pyplot as plt
import numpy as np

# Generate sample data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# First subplot
plt.subplot(1, 2, 1)
plt.plot(x, y1, color="red")
plt.title("Sine Function")

# Second subplot
plt.subplot(1, 2, 2)
plt.plot(x, y2, color="purple")
plt.title("Cosine Function")

# Show the plot
plt.show()

I have executed the above example code and added the screenshot below.

Set Titles for Each Subplot and an Overall Title in Matplotlib

Here, I directly call plt.title() for each subplot. While it’s less flexible than set_title(), it’s still a handy method if you’re working with quick plots.

Add an Overall Title in Python Matplotlib

Sometimes, you also want one big title that describes the entire figure. This overall title helps your audience understand the main idea behind all the subplots.

Let me show you two different methods I use to add an overall title in Matplotlib.

Method 1 – Use Python’s plt.suptitle()

The easiest way to add an overall title is by using plt.suptitle(). This method places the title at the top of the entire figure, above all subplots.

import matplotlib.pyplot as plt
import numpy as np

# Generate data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))

# Plot data
ax1.plot(x, y1, color="blue")
ax2.plot(x, y2, color="green")

# Add subplot titles
ax1.set_title("Sine Wave")
ax2.set_title("Cosine Wave")

# Add overall title
plt.suptitle("Trigonometric Functions in Python")

plt.show()

I have executed the above example code and added the screenshot below.

Set Titles for Each Subplot and Overall Title in Matplotlib

This method is my go-to when I want a quick and clear overall title. It works best for simple figures with one row or one column of subplots.

Method 2 – Use Python’s fig.suptitle()

Another way is to use fig.suptitle(), which gives you more control since you’re working directly with the Figure object. This is especially useful when you’re building complex figures with many subplots.

import matplotlib.pyplot as plt
import numpy as np

# Generate data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)

# Create subplots
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))

# Plot data
ax1.plot(x, y1, color="orange")
ax2.plot(x, y2, color="brown")

# Add subplot titles
ax1.set_title("Sine Function")
ax2.set_title("Cosine Function")

# Add overall title using fig object
fig.suptitle("Trigonometric Functions Overview", fontsize=16, fontweight="bold")

plt.show()

I have executed the above example code and added the screenshot below.

Matplotlib Set Titles for Each Subplot and an Overall Title

I prefer this method when I want to adjust the font size, weight, or alignment of the overall title. It gives me more customization options.

Why Setting Titles Matters in Python Matplotlib

When I present data to clients or colleagues in the USA, I always make sure my charts are clear.

Titles help people instantly understand what they’re looking at. Whether it’s sales trends, weather patterns, or financial growth, a good title makes your chart more professional.

In Python Matplotlib, setting both subplot titles and an overall title ensures that your audience doesn’t get lost in the details.

Tips for Better Titles in Python Matplotlib

  • Keep titles short and clear.
  • Use consistent font sizes across subplot titles.
  • Add an overall title only when it adds real value.
  • If you’re presenting to a US-based audience, use familiar units like Fahrenheit, miles, or dollars.

In this tutorial, I showed you how to set titles for each subplot and also add an overall title in Python Matplotlib.

We covered two methods for Matplotlib subplot titles:

  • Using Axes.set_title()
  • Using plt.title() with plt.subplot()

And two methods for overall titles:

  • Using plt.suptitle()
  • Using fig.suptitle()

Both approaches are simple and effective. I use them regularly in my work, and they make my charts look polished and easy to read.

You may also like to read other Matplotlib-related articles:

Leave a Comment

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.