# Seaborn Subplots: Multiple Plots in One Figure With ax=

> To draw Seaborn plots on subplots, create a grid with fig, axes = plt.subplots(rows, cols) and pass ax=axes[i] to sns.histplot, sns.scatterplot, or any other axes-level function.

Source: https://www.pythoncharts.com/seaborn/seaborn-subplots/ | Published: 2026-12-05 | Author: Alex Scott | Category: Seaborn | Tags: seaborn, subplots, axes-level, ax, suptitle, legend

To put several Seaborn plots in one figure, create the grid with Matplotlib's `fig, axes = plt.subplots(nrows, ncols)` and pass one of the Axes to each Seaborn call with `ax=`, for example `sns.histplot(data=df, x="temp", ax=axes[0])`. This works with every axes-level function (`histplot`, `scatterplot`, `boxplot`, `lineplot`, `heatmap`, and so on). Figure-level functions like `relplot` and `catplot` ignore `ax=`. The examples use Seaborn 0.13.2 and Matplotlib 3.11.

## Quick Example

```python
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns

# Simulated daily readings from five weather stations for one year
rng = np.random.default_rng(29)
days = pd.date_range("2025-01-01", "2025-12-31", freq="D")
season = -np.cos(2 * np.pi * (days.day_of_year - 15) / 365)  # -1 in mid-January, +1 in mid-July
frames = []
for station, offset, swing, wind in [("Harbor", 2.0, 7, 6.5), ("Airport", 0.5, 11, 5.0),
                                     ("Hilltop", -2.5, 10, 7.5), ("Riverside", 1.0, 9, 3.5),
                                     ("Downtown", 2.5, 10, 3.0)]:
    temp = 12 + offset + swing * season + rng.normal(0, 2.5, len(days))
    frames.append(pd.DataFrame({
        "date": days, "station": station, "temp_c": temp.round(1),
        "humidity": np.clip(78 - 1.2 * (temp - 12) + rng.normal(0, 8, len(days)), 20, 100).round(),
        "wind_kmh": rng.gamma(4, wind / 4, len(days)).round(1),
    }))
weather = pd.concat(frames, ignore_index=True)

sns.set_theme(style="whitegrid")
fig, axes = plt.subplots(1, 2, figsize=(11, 4.2))
sns.histplot(data=weather, x="temp_c", color="#e07a5f", ax=axes[0])
sns.scatterplot(data=weather, x="temp_c", y="humidity", alpha=0.25, s=12, color="#3d405b", ax=axes[1])
axes[0].set(title="Daily temperature", xlabel="Temperature (°C)")
axes[1].set(title="Warmer days are drier", xlabel="Temperature (°C)", ylabel="Humidity (%)")
fig.tight_layout()
plt.show()
```

![Two Seaborn plots side by side in one figure: a histogram of daily temperature from about -6 to 30 degrees C on the left, and a scatter plot on the right showing humidity falling from near 100 percent on cold days to about 60 percent on warm days](https://www.pythoncharts.com/seaborn/seaborn-subplots/images/seaborn-subplots-quick-example.png)

`plt.subplots(1, 2)` returns the figure and a NumPy array of two Axes. Each Seaborn call draws on the Axes you give it and returns that same Axes.

## How does `ax=` work in Seaborn?

Seaborn's axes-level functions draw on one Matplotlib Axes. If you pass `ax=`, they draw there. If you don't, they draw on the current Axes (`plt.gca()`), which is the last one created. That's why calling `sns.histplot()` twice without `ax=` stacks both histograms on the same plot.

Every axes-level function returns the Axes it drew on, so you can also write `ax = sns.boxplot(...)` and then customize `ax`. The figure-level functions (`relplot`, `displot`, `catplot`, `lmplot`, `jointplot`, `pairplot`) build their own figure and can't be placed in a subplot. See [figure-level vs axes-level functions](https://www.pythoncharts.com/seaborn/seaborn-figure-level-vs-axes-level/) for the full list.

| Figure-level (no `ax=`) | Axes-level equivalents (take `ax=`) |
|---|---|
| `sns.relplot` | `sns.scatterplot`, `sns.lineplot` |
| `sns.displot` | `sns.histplot`, `sns.kdeplot`, `sns.ecdfplot` |
| `sns.catplot` | `sns.boxplot`, `sns.violinplot`, `sns.barplot`, `sns.stripplot`, `sns.countplot`, and the other categorical plots |
| `sns.lmplot` | `sns.regplot` |

## A 2×2 grid of different Seaborn plots

With more than one row, `axes` is a 2D array, so index it with `axes[row, col]`. Each panel can be a different kind of chart:

```python
fig, axes = plt.subplots(2, 2, figsize=(11, 8))
monthly = weather.assign(month=weather["date"].dt.month)

sns.lineplot(data=monthly, x="month", y="temp_c", hue="station", errorbar=None, ax=axes[0, 0])
sns.boxplot(data=weather, x="station", y="wind_kmh", color="#81b29a", ax=axes[0, 1])
sns.kdeplot(data=weather, x="humidity", hue="station", common_norm=False, cut=0, ax=axes[1, 0])
sns.heatmap(monthly.pivot_table(index="station", columns="month", values="temp_c"),
            annot=True, fmt=".0f", cmap="coolwarm", cbar=False, ax=axes[1, 1])

axes[0, 0].set(title="Monthly mean temperature", xlabel="Month", ylabel="°C")
axes[0, 1].set(title="Wind speed by station", xlabel="", ylabel="km/h")
axes[1, 0].set(title="Humidity distribution", xlabel="Humidity (%)")
axes[1, 1].set(title="Mean temperature (°C)", xlabel="Month", ylabel="")
sns.move_legend(axes[0, 0], "upper left", ncols=2, fontsize=8, title=None)
sns.move_legend(axes[1, 0], "upper left", fontsize=8, title=None)
fig.tight_layout()
plt.show()
```

![A 2 by 2 grid of different Seaborn plots: monthly temperature lines for five weather stations, box plots of wind speed by station with Hilltop windiest, humidity density curves, and an annotated heatmap of mean temperature by station and month](https://www.pythoncharts.com/seaborn/seaborn-subplots/images/seaborn-subplots-grid.png)

The four panels show the same stations from four angles. Hilltop is the coldest station all year (-0.9 °C in January, 19.6 °C in July) and the windiest (median 6.6 km/h). Harbor has the smallest seasonal swing: 14 °C between January and July, against 17 to 21 °C at the other stations. `cbar=False` drops the heatmap's colorbar because the values are printed in the cells, and the `move_legend` calls shrink the line and density legends so they don't cover the data.

## Loop over groups to fill the subplots

To draw the same chart once per group, zip the flattened Axes array with a `groupby`. `axes.flat` walks the grid row by row, so the loop works for any grid shape. Five stations in a 2×3 grid leave one empty panel, which `ax.set_visible(False)` hides:

```python
fig, axes = plt.subplots(2, 3, figsize=(11, 6.5), sharex=True, sharey=True)
for ax, (station, df) in zip(axes.flat, weather.groupby("station")):
    sns.histplot(data=df, x="wind_kmh", binwidth=1, color="#5b7db1", ax=ax)
    ax.set_title(f"{station} (median {df['wind_kmh'].median():.1f} km/h)")
    ax.set(xlabel="", ylabel="")
for ax in axes.flat[weather["station"].nunique():]:
    ax.set_visible(False)
axes[0, 2].tick_params(labelbottom=True)  # the panel below it is hidden

fig.suptitle("Daily wind speed by station, 2025", fontsize=15)
fig.supxlabel("Wind speed (km/h)")
fig.supylabel("Days")
fig.tight_layout()
plt.show()
```

![Five Seaborn histograms of daily wind speed, one per weather station, in a 2 by 3 grid with shared axes, an empty sixth panel hidden, and one figure title and shared axis labels; Hilltop has the widest spread and Downtown the calmest days](https://www.pythoncharts.com/seaborn/seaborn-subplots/images/seaborn-subplots-loop.png)

`sharex=True` hides the x tick labels on every row but the bottom one, so the last line turns them back on for the panel above the hidden one.

With `sharex=True` and `sharey=True`, every panel has the same axis ranges, so you can compare the stations at a glance. Without them, each histogram scales to its own data and a calm station looks as windy as a windy one. `fig.supxlabel()` and `fig.supylabel()` (Matplotlib 3.4+) put one label on the whole figure instead of repeating it on every panel.

If every panel is the same chart split by one column, a figure-level function does all of this for you: `sns.displot(data=weather, x="wind_kmh", col="station", col_wrap=3, binwidth=1)` builds the same grid without the loop. Use the loop when you need control the `FacetGrid` doesn't give you, such as a different title format per panel or extra Matplotlib drawing.

## Set the title and axis labels on each subplot

Axes-level plots don't take `title=` or `xlabel=` arguments. Set them on the Axes after drawing:

- `ax.set_title("...")` for the subplot title (`loc="left"` aligns it left).
- `ax.set_xlabel("...")` and `ax.set_ylabel("...")`, or all three at once with `ax.set(title=..., xlabel=..., ylabel=...)`. Set a label to `""` to remove it.
- `fig.suptitle("...")` for one title above the whole figure.

`plt.title()` and `plt.xlabel()` also work, but they change only the current Axes, which is the last one created, not necessarily the one you just drew on. With subplots, call the Axes methods instead. For figure-level functions, the methods live on the grid instead: [FacetGrid titles](https://www.pythoncharts.com/seaborn/seaborn-facetgrid-titles/) covers `g.set_titles()` and `g.set_axis_labels()`.

## Use one shared legend for all the subplots

When every panel uses the same `hue`, each one draws the same legend. Turn them off with `legend=False` on all but one plot, take that plot's handles, and give them to `fig.legend()`:

```python
palette = dict(zip(sorted(weather["station"].unique()), sns.color_palette("Set2", 5)))
fig, axes = plt.subplots(1, 3, figsize=(12, 4), layout="constrained")
sns.kdeplot(data=weather, x="temp_c", hue="station", palette=palette, ax=axes[0])
sns.kdeplot(data=weather, x="humidity", hue="station", palette=palette, legend=False, cut=0, ax=axes[1])
sns.kdeplot(data=weather, x="wind_kmh", hue="station", palette=palette, legend=False, cut=0, ax=axes[2])
for ax, label in zip(axes, ["Temperature (°C)", "Humidity (%)", "Wind speed (km/h)"]):
    ax.set(xlabel=label, ylabel="")
axes[0].set_ylabel("Density")

legend = axes[0].get_legend()
fig.legend(legend.legend_handles, [t.get_text() for t in legend.get_texts()],
           loc="outside upper center", ncols=5, frameon=False)
legend.remove()
plt.show()
```

![Three Seaborn density plots in a row for temperature, humidity, and wind speed, each with one curve per station, and a single legend above all three panels](https://www.pythoncharts.com/seaborn/seaborn-subplots/images/seaborn-subplots-shared-legend.png)

`loc="outside upper center"` puts the legend above the panels without covering them. It only works on a figure created with `layout="constrained"`, which is why this example passes it to `plt.subplots()`. The `fig.legend()` call reuses the first plot's legend entries, so the colors are guaranteed to match, and passing the same `palette` dict to every call keeps each station's color the same across panels. For a single plot, [`sns.move_legend`](https://www.pythoncharts.com/seaborn/seaborn-move-legend/) is simpler.

## Common errors with Seaborn subplots

- **`AttributeError: 'numpy.ndarray' object has no attribute 'set_title'`**: you called a method on the whole `axes` array. Pick one Axes first: `axes[0].set_title(...)`, or `axes[0, 1]` in a 2D grid. The [`'Axes' object has no attribute` post](https://www.pythoncharts.com/matplotlib/matplotlib-axes-object-has-no-attribute/) covers this and related errors.
- **`UserWarning: relplot is a figure-level function and does not accept the ax parameter. You may wish to try scatterplot`**: figure-level functions draw a new figure and leave your subplot empty. Use the axes-level function named in the warning. `catplot` and `displot` print similar warnings.
- **Two charts drawn on top of each other**: a Seaborn call is missing `ax=`, so it drew on the current Axes.
- **Overlapping titles and tick labels**: call `fig.tight_layout()` or create the figure with `layout="constrained"`. See [tight_layout and subplot spacing](https://www.pythoncharts.com/matplotlib/matplotlib-tight-layout-subplot-spacing/).
- **`IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed`**: a grid with one row or one column returns a 1D array, so use `axes[i]`, not `axes[0, i]`. Pass `squeeze=False` to always get a 2D array.

## Subplots or a FacetGrid: which should you use?

| You want | Use |
|---|---|
| Different chart types side by side | `plt.subplots()` and `ax=` |
| The same chart for each value of a column | `sns.relplot`, `sns.displot`, or `sns.catplot` with `col=` / `row=` |
| Seaborn charts mixed with plain Matplotlib or other libraries | `plt.subplots()` and `ax=` |
| Panels of different sizes | [`plt.subplot_mosaic()`](https://www.pythoncharts.com/matplotlib/matplotlib-subplot-mosaic-gridspec/), then `ax=` |
| Every pair of numeric columns | `sns.pairplot` |

## Practical Tips

- **Set the figure size in `plt.subplots(figsize=...)`.** About 4 to 5 inches of width per column keeps tick labels readable.
- **Use the same `palette` dict in every call** so a group keeps one color across panels.
- **Turn on `sharex`/`sharey` when panels are meant to be compared**, and leave them off when the panels show different variables.
- **Save the whole figure** with `fig.savefig("weather.png", dpi=150, bbox_inches="tight")`, not with `ax`.

## Similar Topics

- [Seaborn figure-level vs axes-level functions](https://www.pythoncharts.com/seaborn/seaborn-figure-level-vs-axes-level/)
- [Matplotlib subplots](https://www.pythoncharts.com/matplotlib/matplotlib-subplots/)
- [Titles in Seaborn FacetGrid, relplot, and catplot](https://www.pythoncharts.com/seaborn/seaborn-facetgrid-titles/)
