Plot guides › Chart types

Grouped bar chart

A grouped (clustered) bar chart places a bar for each subgroup next to the others inside every category, so you can compare subgroups directly within a category.

Example grouped bar chart made with matplotlib
Rendered from the code below, with example data.

When to use it

Watch out: Beyond three or four bars per group, it gets hard to read. Consider small multiples or a line chart.

Ask for it in pltchat

Upload your file and type something like:

"grouped bar chart: quarter on x, one bar per region"

pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.

The matplotlib code

Self-contained with example data; swap in pd.read_csv(...) or pd.read_excel(...) for your own file.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({"quarter": ["Q1", "Q2", "Q3", "Q4"],
                   "North": [20, 34, 30, 35],
                   "South": [25, 32, 34, 20],
                   "West": [18, 22, 28, 31]}).set_index("quarter")

x = np.arange(len(df))
width = 0.8 / len(df.columns)
fig, ax = plt.subplots(figsize=(6.4, 4))
for i, col in enumerate(df.columns):
    ax.bar(x + (i - (len(df.columns) - 1) / 2) * width, df[col], width, label=col)
ax.set_xticks(x, df.index)
ax.set_ylabel("Sales (k$)")
ax.legend(title="Region")
ax.spines[["top", "right"]].set_visible(False)
plt.tight_layout()
plt.show()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots