plotting
matplotlib
subplot
main title
data visualization

How to set a single, main title above all the subplots

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Matplotlib, a title for the entire figure should usually be attached to the Figure, not to any individual Axes. The standard tool for that is fig.suptitle(), which creates one title above all subplots.

The main complication is layout. Once you add a figure-level title, you often need to adjust tight_layout, constrained_layout, or subplot spacing so the title does not overlap the axes.

Use suptitle on the Figure

python
1import matplotlib.pyplot as plt
2
3fig, axes = plt.subplots(2, 2, figsize=(8, 6))
4
5for ax in axes.flat:
6    ax.plot([1, 2, 3], [1, 4, 9])
7
8fig.suptitle("Main figure title", fontsize=16)
9plt.show()

This places one title above the whole grid, not inside any single subplot.

That distinction matters because figure-level layout and axes-level layout are managed separately in Matplotlib.

Why ax.set_title() Is Not the Right Tool

ax.set_title() applies only to one subplot:

python
axes[0, 0].set_title("Only this subplot")

That is useful for panel-specific labels, but it is not a replacement for a global title. If you want both, combine them:

  • 'fig.suptitle() for the whole figure'
  • 'ax.set_title() for each subplot'

Avoid Overlap with tight_layout

The common pitfall is that the figure title overlaps the top row of subplots when tight_layout() compresses everything.

One fix is to leave room explicitly:

python
1import matplotlib.pyplot as plt
2
3fig, axes = plt.subplots(2, 2, figsize=(8, 6))
4
5for ax in axes.flat:
6    ax.plot([1, 2, 3], [1, 4, 9])
7
8fig.suptitle("Main figure title", fontsize=16)
9plt.tight_layout(rect=[0, 0, 1, 0.95])
10plt.show()

The rect argument reserves the top part of the figure for the title.

Use constrained_layout in Newer Code

Another option is to let Matplotlib manage spacing more automatically:

python
1import matplotlib.pyplot as plt
2
3fig, axes = plt.subplots(2, 2, figsize=(8, 6), constrained_layout=True)
4
5for ax in axes.flat:
6    ax.plot([1, 2, 3], [1, 4, 9])
7
8fig.suptitle("Main figure title", fontsize=16)
9plt.show()

constrained_layout is often easier than manually tuning subplot spacing, especially when labels, legends, and titles all compete for room.

It is especially helpful in notebooks and quick analysis scripts where you want a decent default layout without manually tweaking subplot margins every time.

A Useful Pattern with Individual Titles

python
1import matplotlib.pyplot as plt
2
3fig, axes = plt.subplots(1, 3, figsize=(10, 4))
4fig.suptitle("Model comparison", fontsize=15)
5
6titles = ["Baseline", "Tuned", "Production"]
7
8for ax, title in zip(axes, titles):
9    ax.plot([0, 1, 2], [0, 1, 0])
10    ax.set_title(title)
11
12plt.tight_layout(rect=[0, 0, 1, 0.92])
13plt.show()

This creates a clear hierarchy:

  • figure title for the overall meaning
  • subplot titles for local meaning

That visual hierarchy is usually what people actually want when they ask for one main title above multiple subplot panels.

It also keeps figure-level meaning separate from panel-level meaning, which makes multi-plot reports much easier to read.

That separation is a small detail, but it improves readability immediately in dashboards, notebooks, and exported reports.

Common Pitfalls

  • Using ax.set_title() and expecting it to become a figure-wide title.
  • Calling tight_layout() without leaving room for suptitle().
  • Adding the title after saving or rendering the figure and wondering why it is missing.
  • Mixing manual spacing tweaks and constrained_layout without understanding which layout system is active.
  • Making the figure title too large for the available top margin.

Summary

  • Use fig.suptitle() for one title above all subplots.
  • Use ax.set_title() only for subplot-specific titles.
  • Reserve room with tight_layout(rect=...) if overlap occurs.
  • 'constrained_layout=True is often the easiest modern layout option.'
  • Figure-wide and subplot-specific titles can be used together when spaced correctly.

Course illustration
Course illustration

All Rights Reserved.