Skip to content
svgfunnel

Funnel

Where do people drop out of a multi-step process?

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

How to read it

  1. Read top to bottom: each row is a stage.
  2. Read the share on the right against the first stage.
  3. Read the step conversion for the biggest drop between neighbours.
  1. Callout 1: The first stage: everyone who started.
  2. Callout 2: The biggest narrowing: the step to investigate.
  3. Callout 3: Overall share, and share of the previous stage.

Watch out

  • It compares counts at one time. Users still in progress can look like drop-off unless you fix a window.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Stages in declared level order (else first appearance); value = sum of the count column or rows per stage.
  • Overall conversion = stage / first stage; step conversion = stage / previous stage.
  • Bar width ∝ value on a linear scale (not area); connectors show the step loss.
  • A funnel assumes each stage is a subset of the previous one; check that the counts never increase.
# Funnel — Codesplash Chart Lab (recipe "funnel")
# controls: defaults
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("funnel-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["stage"] = pd.Categorical(df["stage"].astype("string"), categories=["Visited", "Viewed product", "Added to cart", "Checkout", "Purchased"])

d = df[df["stage"].notna()].copy()
d["_k"] = d["stage"].astype(str)
d["_v"] = 1.0  # no value column: count rows
sums = d.groupby("_k", sort=False)["_v"].sum()  # first-appearance order
if isinstance(df["stage"].dtype, pd.CategoricalDtype):  # declared order first
    declared = [str(l) for l in df["stage"].cat.categories]
    sums = sums.reindex([l for l in declared if l in sums.index] + [s for s in sums.index if s not in declared])
f = sums.rename("value").rename_axis("stage").reset_index()
f["overall"] = f["value"] / f["value"].iloc[0]  # conversion from the first stage
f["step"] = (f["value"] / f["value"].shift(1)).fillna(1.0)  # conversion from the previous stage

fig, ax = plt.subplots(figsize=(8, 4.5))
y = np.arange(len(f))[::-1]  # first stage on top
ax.barh(y, f["value"], left=-f["value"] / 2, color=PALETTE[0], height=0.72)  # width ∝ value, centred
for yi, r in zip(y, f.itertuples()):
    ax.text(0, yi, f"{r.value:,.0f}", ha="center", va="center", color="white", fontsize=8, fontweight="bold")
    ax.text(f["value"].max() / 2 * 1.04, yi, f"{r.overall:.1%} of first · {r.step:.1%} of previous", va="center", fontsize=7.5)
ax.set_yticks(y, f["stage"])
ax.set_xticks([])
ax.set_xlim(-f["value"].max() / 2 * 1.05, f["value"].max() * 1.15)
ax.grid(False)
plt.show()

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