Skip to content
svgbrushablecleveland-dot

Cleveland dot plot

How do categories compare on one value — and across up to three groups?

Demo data · seed 20261101 · 480 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Compare the dots in a row to see how the groups differ inside one category.
  2. Read the line joining them as the size of that gap.
  3. Read the column of dots down the rows for how one group changes across categories.
  1. Callout 1: One dot per group in this row.
  2. Callout 2: The line joining dots: the gap between groups.
  3. Callout 3: No zero baseline: the axis zooms to the data's range.

Watch out

  • The axis doesn't start at zero, so gaps look large. Check the scale before calling one big.

Defaults

Aggregate
Mean
How rows combine into one number per group or period, such as a sum or a mean.
Also: Sum · Median · Count
Top N
12
How many categories to show.
Range 3 to 30, step 1
Sort
By value
How rows are sorted.
Also: Alphabetical

Pinned in the code

  • Position on a common scale is the most accurately judged encoding (Cleveland & McGill 1984); the axis need not include zero because dots are read by position, not length.
  • Rows are sorted by the aggregate over all rows (sum, mean, type-7 median or count); the first three group levels by frequency get a dot each.
  • A thin segment spans the group values on a row so gaps are easy to read.
# Cleveland dot plot — Codesplash Chart Lab (recipe "cleveland-dot")
# controls: stat=mean, top=12, sort=value
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("cleveland-dot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["sex"] = pd.Categorical(df["sex"].astype("string"), categories=["Female", "Male"])

def levels(s):
    """Level order like the app: declared order (categorical dtype), else by descending frequency, ties alphabetical."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [str(c) for c in s.cat.categories]
    counts = s.dropna().astype(str).value_counts()
    return sorted(counts.index, key=lambda k: (-counts[k], k))

d = df.dropna(subset=["country", "life_expectancy"]).copy()
d["_cat"] = d["country"].astype(str)
overall = d.groupby("_cat")["life_expectancy"].agg("mean").rename("overall").reset_index()  # orders the rows
overall = overall[np.isfinite(overall["overall"].astype(float))]
overall = overall.sort_values(["overall", "_cat"], ascending=[False, True]).head(12)  # ties alphabetical
groups = levels(df["sex"])[:3]  # first three group levels (dictionary order, else frequency)
d = d[d["sex"].notna()]
d["_g"] = d["sex"].astype(str)
cells = d[d["_g"].isin(groups)].groupby(["_cat", "_g"])["life_expectancy"].agg("mean").unstack()
cells = cells.reindex(index=overall["_cat"], columns=groups)

fig, ax = plt.subplots(figsize=(7, 5))
y = np.arange(len(cells))[::-1]  # first row on top
ax.hlines(y, cells.min(axis=1), cells.max(axis=1), color="#9aa0a6", linewidth=2, zorder=1)  # span of the group values
for j, grp in enumerate(groups):
    ax.scatter(cells[grp], y, s=48, color=PALETTE[j], label=grp, zorder=2)
ax.set_yticks(y, cells.index)
ax.set_xlabel("Mean life_expectancy")  # no zero baseline: dots are read by position
ax.set_ylabel("country")
ax.legend(title="sex")
plt.show()

Needs pandas, numpy, matplotlib · reads cleveland-dot-demo.csv · app theme from the optional codesplash helper