Sub topic 11
Before/after charts and drilling down
A Pareto chart tells you where to start. Two follow-up questions come next: did the fix work, and what is going on inside the biggest bar? Before/after comparisons answer the first. Drill-down charts answer the second.
This chapter assumes you can already build and read a single Pareto chart: sorted bars, a cumulative-percentage line, and an "Other" bar placed last. It also assumes basic pandas and matplotlib. The code reuses the defect data from the earlier chapters.
Why one chart is not enough
A single Pareto chart is a snapshot. It ranks causes for one period and one scope. Improvement work needs two more views:
- A comparison over time. After you act on the top category, you collect new data and compare it with the old data. This shows whether the fix worked and whether the problem moved somewhere else.
- A zoomed-in view. The top category is often still too broad to act on. "Scratches" is a symptom, not a cause. You split it by a second factor, such as station, shift, machine, or material, and build a new Pareto chart from that subset.
Both views reuse the same chart type. The difficulty is keeping the comparison fair.
Building a fair before/after comparison
Three rules prevent most misleading comparisons.
- Use the same categories and the same definitions. If "Misalignment" meant something different in the second period, the bars are not comparable.
- Use the same measure. Compare counts with counts, or cost with cost.
- Account for volume. If the two periods inspected different numbers of units, convert counts to rates, such as defects per 1,000 units.
Fix the category order
Sort the categories by the before data and keep that order for the after chart. Readers can then compare bar against bar without hunting for labels. Keep "Other" last in both charts.
The after data may rank the categories differently. That is useful information, and you can still read it from the fixed-order chart. For the "new vital few", re-sort the after data separately. A fixed order is for comparing categories. A re-sorted chart is for finding the next priority.
Compare rates, not only counts
Suppose the first period inspected 5,000 units and the second inspected 4,000. The raw counts hide the volume difference.
import pandas as pd
before = pd.Series({
"Scratches": 42, "Misalignment": 27, "Wrong label": 11,
"Cracks": 8, "Discoloration": 5, "Other": 7,
})
after = pd.Series({
"Scratches": 15, "Misalignment": 26, "Wrong label": 10,
"Cracks": 8, "Discoloration": 5, "Other": 6,
})
units = pd.Series({"before": 5000, "after": 4000})
# Order set by the "before" data, with "Other" last in both periods
order = before.drop("Other").sort_values(ascending=False).index.tolist() + ["Other"]
compare = pd.DataFrame({"before": before, "after": after}).loc[order]
compare["count_change_pct"] = (
(compare["after"] / compare["before"] - 1) * 100
).round(1)
# Defects per 1,000 units inspected (columns line up with the units index)
rate = compare[["before", "after"]] / units * 1000
compare["rate_before"] = rate["before"].round(2)
compare["rate_after"] = rate["after"].round(2)
compare["rate_change_pct"] = ((rate["after"] / rate["before"] - 1) * 100).round(1)
print(compare)
print(compare[["before", "after"]].sum())The totals are 100 defects before and 70 after. The per-category results are:
| Category | Count change | Rate before | Rate after | Rate change |
|---|---|---|---|---|
| Scratches | -64.3% | 8.40 | 3.75 | -55.4% |
| Misalignment | -3.7% | 5.40 | 6.50 | +20.4% |
| Wrong label | -9.1% | 2.20 | 2.50 | +13.6% |
| Cracks | 0.0% | 1.60 | 2.00 | +25.0% |
| Discoloration | 0.0% | 1.00 | 1.25 | +25.0% |
| Other | -14.3% | 1.40 | 1.50 | +7.1% |
The raw total fell by 30%. The rate fell only from 20.0 to 17.5 defects per 1,000 units, a 12.5% drop. The scratch fix clearly worked. Misalignment looked flat by count but got worse by rate.
Plotting the pair side by side
Place the two charts next to each other with a shared vertical axis. If each chart chooses its own scale, a small after bar can look as tall as a large before bar.
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import PercentFormatter
before = pd.Series({
"Scratches": 42, "Misalignment": 27, "Wrong label": 11,
"Cracks": 8, "Discoloration": 5, "Other": 7,
})
after = pd.Series({
"Scratches": 15, "Misalignment": 26, "Wrong label": 10,
"Cracks": 8, "Discoloration": 5, "Other": 6,
})
order = before.drop("Other").sort_values(ascending=False).index.tolist() + ["Other"]
fig, axes = plt.subplots(1, 2, figsize=(11, 4.5), sharey=True)
for ax, series, title in zip(axes, [before, after], ["Before", "After"]):
data = series.loc[order]
cum_pct = data.cumsum() / data.sum() * 100
ax.bar(data.index, data.values, color="C0")
ax.set_title(f"{title} (total {data.sum()})")
ax.tick_params(axis="x", rotation=30)
ax2 = ax.twinx()
ax2.plot(data.index, cum_pct.values, color="C1", marker="o")
ax2.set_ylim(0, 100)
ax2.yaxis.set_major_formatter(PercentFormatter())
ax2.axhline(80, color="gray", linestyle="--", linewidth=1)
axes[0].set_ylabel("Defect count")
fig.tight_layout()
plt.show()sharey=True keeps the left axis identical on both panels. Each cumulative line is scaled to its own total, so the right axis always runs from 0 to 100%.
Reading the pair
Look at four things, in this order:
- The tallest bar's height. Did the targeted category drop? Here Scratches fell from 42 to 15.
- The other bars. Did they stay level, or did they rise? A rise may mean the problem moved, or that the process change had side effects.
- The shape of the cumulative line. After a successful fix on the top category, the curve usually flattens. The vital few become less dominant.
- The new ranking. Misalignment is now the largest bar. Re-sort the after data to find the next vital few:
import pandas as pd
after = pd.Series({
"Scratches": 15, "Misalignment": 26, "Wrong label": 10,
"Cracks": 8, "Discoloration": 5, "Other": 6,
})
main = after.drop("Other").sort_values(ascending=False)
data = pd.concat([main, after[["Other"]]])
cum_pct = data.cumsum() / data.sum() * 100
vital_few = data[cum_pct.shift(fill_value=0) < 80]
print(vital_few)
print(f"{len(vital_few)} of {len(data)} categories give {vital_few.sum() / data.sum():.0%} of defects")The cumulative shares are 37.1%, 58.6%, 72.9%, 84.3%, 90.0% and 100%. So four categories (Misalignment, Scratches, Wrong label, Cracks) are needed to pass 80%, where three were needed before. The distribution is flatter, and that is a normal result of fixing the biggest problem.
Drilling down into the top category
A drill-down chart is a Pareto chart built from only the records in one category, split by a second factor. The raw data needs at least two columns: the original category and the new splitting factor.
This code builds the drill-down for scratches, split by the station where each defect was recorded:
import pandas as pd
records = pd.DataFrame(
[("Scratches", "Conveyor 3")] * 24
+ [("Scratches", "Packing")] * 9
+ [("Scratches", "Hand cart")] * 5
+ [("Scratches", "Unknown")] * 4
+ [("Misalignment", "Press 2")] * 27,
columns=["defect", "station"],
)
def pareto_table(values, last=None):
"""Counts sorted descending, with an optional catch-all label kept last."""
counts = values.value_counts()
if last in counts.index:
counts = pd.concat([counts.drop(last), counts[[last]]])
cum_pct = counts.cumsum() / counts.sum() * 100
return pd.DataFrame({"count": counts, "cumulative_pct": cum_pct.round(1)})
scratches = records.loc[records["defect"] == "Scratches", "station"]
print(pareto_table(scratches, last="Unknown"))The output shows Conveyor 3 with 24 scratches (57.1% cumulative), Packing with 9 (78.6%), Hand cart with 5 (90.5%) and Unknown with 4 (100.0%). One station accounts for more than half of the scratches. Now the team has something concrete to inspect.
Choosing the splitting factor
Pick a factor that you can act on and that you recorded for every defect. Common choices are station, machine, shift, supplier, product type, and operator team. If many records fall into "Unknown", the drill-down is weak, and the first improvement may be to fix the data collection.
You can drill down more than once, for example scratches, then Conveyor 3, then shift. Stop when a category becomes small enough that a single cause explains it, or when the counts are too low to be reliable. A bar of three records is an anecdote, not a pattern.
Common mistakes
| Mistake | Effect | Remedy |
|---|---|---|
| Different category order on each chart | Readers cannot match bars across charts | Fix the order from the before data |
| Independent y-axes | Small bars look as large as big ones | Share the y-axis on both panels |
| Comparing counts from unequal volume | A false improvement, or a hidden decline | Use rates per unit, hour or order |
| Changing category definitions mid-project | The comparison is invalid | Freeze definitions, or re-code the old data |
| Drilling into "Other" | Wasted effort on tiny categories | Drill into the largest named category |
| Declaring success from one short period | Normal variation looks like a trend | Collect several periods before concluding |
| Reading drill-down shares as whole-process shares | Overstated impact | Multiply by the parent's share |
A final caution concerns time. A single before and a single after period cannot separate your fix from ordinary variation. If counts are small, a drop from 12 to 9 may be noise. Where possible, collect several periods on each side, or run a statistical check before you announce the result.
Exercise
A line inspected 2,000 units in March and had 50 defects. In April it inspected 3,000 units and had 60 defects. The raw counts rose from 50 to 60. What happened to the defect rate per 1,000 units, and what should you conclude?
Show answer
March: 50 / 2,000 × 1,000 = 25 defects per 1,000 units. April: 60 / 3,000 × 1,000 = 20 per 1,000. The rate fell by 20%, even though the count rose. The quality improved. The raw count rose only because more units were inspected.
Exercise
In a drill-down, the top station accounts for 60% of the scratches, and scratches are 35% of all defects. What share of all defects comes from that station? Why would you report that figure instead of 60%?
Show answer
0.60 × 35% = 21% of all defects. The 60% is relative to scratches only. The 21% shows the effect of fixing that station on the whole process, so it is the figure to use when comparing the work against other priorities.