Skip to content
svgbrushablepareto

Pareto chart

Which few categories account for most of the total?

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

How to read it

  1. Read the bars left to right: categories are sorted by size.
  2. Follow the line for the running share of the total.
  3. Where the line crosses the reference: everything left of it is the vital few.
  1. Callout 1: The largest category.
  2. Callout 2: The running total crosses the reference here.
  3. Callout 3: The long tail of small categories.

Watch out

  • It ranks frequency, not cost or severity. The biggest bar is not always the most important problem.

Defaults

Categories shown
10
How many categories to show before grouping the rest into Other.
Range 3 to 30, step 1
Reference %
80
Where to draw the reference line on the cumulative axis.
Range 50 to 95, step 5
Cumulative labels
Off
Print the running share at each bar.

Pinned in the code

  • Bars are row counts (or the sum of a value) per category, sorted descending (ties alphabetical); categories beyond the first N pool into “Other”, which is kept last as is conventional.
  • Cumulative % = running total / grand total, read on the right axis; bars up to and including the one that crosses the reference (80 % by default) are the “vital few”.
  • Negative values are not meaningful in a Pareto chart and are excluded.
# Pareto chart — Codesplash Chart Lab (recipe "pareto")
# controls: top=10, threshold=80, cumLabels=false
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("pareto-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

d = df[["defect"]].dropna().assign(_value=1.0)  # no value column: count rows
sums = d.groupby(d["defect"].astype(str))["_value"].sum()
sums = sums[sums > 0]  # non-positive totals are not meaningful in a Pareto chart
r = sums.rename("value").reset_index().sort_values(["value", "defect"], ascending=[False, True])  # ties alphabetical
r["share"] = r["value"] / r["value"].sum()
r["cumulative"] = r["share"].cumsum()
if len(r) > 10:  # pool the rest into "Other", kept last
    rest = r.iloc[10:]
    other = pd.DataFrame({"defect": ["Other"], "value": [rest["value"].sum()], "share": [rest["share"].sum()], "cumulative": [1.0]})
    r = pd.concat([r.iloc[:10], other], ignore_index=True)
THRESHOLD = 0.8
vital = int(np.argmax(r["cumulative"].to_numpy() >= THRESHOLD - 1e-12))  # bars up to the crossing are the vital few
colors = ["#9aa0a6" if lvl == "Other" else (PALETTE[0] if i <= vital else PALETTE[0] + "73") for i, lvl in enumerate(r["defect"])]

fig, ax = plt.subplots(figsize=(8, 4.5))
ax.bar(r["defect"], r["value"], color=colors)
ax.set_ylabel("Count")
ax.set_xlabel("defect")
ax.tick_params(axis="x", labelrotation=35)
ax2 = ax.twinx()  # cumulative share on a 0–100 % axis
ax2.plot(r["defect"], r["cumulative"] * 100, color=PALETTE[1], marker="o", linewidth=2)
ax2.axhline(THRESHOLD * 100, color=PALETTE[1], linestyle="--", linewidth=1)
ax2.set_ylim(0, 105)
ax2.set_ylabel("Cumulative %")
ax2.grid(False)
plt.show()

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