Sort one additive measure, retain the whole denominator and make the category boundary explicit.
Pareto charts: reconcile the cumulative line to the categories
Start with an additive question
A Pareto chart ranks categories by a nonnegative contribution and traces their cumulative share of the total. The measure could be incident count, repair hours or cost; those are different prioritization questions. State the unit and aggregation grain before sorting. If one ticket appears under several causes, the category totals may exceed the number of tickets. Either allocate each ticket once or label the chart as multi-tag occurrences. Aggregation and denominator rules determine whether the cumulative line has a meaningful one-hundred-percent endpoint.
Keep the total visible
Calculate the percentage from all eligible categories, including the long tail. Grouping minor categories into Other can make a useful display, but the grouped value must equal the sum of the hidden categories and the full total must remain unchanged. A threshold line at eighty percent is only a reading aid; it does not prove an eighty-twenty distribution. Report the smallest number of categories needed to cross the chosen threshold, and name the threshold as a policy choice. Composition charts face the same problem when categories enter or leave the frame.
Separate bar scale from share scale
Bars encode the additive quantity, while the cumulative line encodes a percentage. These are different units, so label both axes and give the percentage line an explicit zero-to-one-hundred range. A dual-axis overlay can be compact, but lines and bars should remain legible independently. Dual-axis integrity matters here because changing the right axis can make the cumulative curve look steeper. A companion table with category, contribution, cumulative contribution and share makes the chart auditable without decoding line height.
Handle ties, zeros and time changes
When two categories have equal contributions, use a stable secondary key so repeated renders keep the same order. Zero categories may remain in the export even if the display omits them. If the chart is refreshed weekly, changing rank order is expected; do not compare bar positions as though category identity stayed fixed. Rank-movement charts are better for that question. If the total is zero, a cumulative percentage is undefined. Show the count table and an explicit no-contributions state rather than drawing a flat zero-percent line.
Worked contract
from math import isfinite
def pareto_rows(contributions: dict[str, float]
) -> list[tuple[str, float, float]]:
if not contributions or any(not name for name in contributions):
raise ValueError("categories must be named")
if any(not isfinite(value) or value < 0
for value in contributions.values()):
raise ValueError("contributions must be finite and nonnegative")
total = sum(contributions.values())
if total <= 0:
raise ValueError("a zero total has no cumulative share")
ordered = sorted(contributions.items(), key=lambda item: (-item[1], item[0]))
running = 0.0
result = []
for category, value in ordered:
running += value
result.append((category, value, running / total))
return result
repair_hours = {"pump seals": 47, "sensor faults": 81,
"cable damage": 29, "other": 43}
priority = pareto_rows(repair_hours)
assert priority[0] == ("sensor faults", 81, 0.405)
assert priority[-1][2] == 1.0Performance and operating cost
For C categories, sorting costs O(C log C) time and output takes O(C) space. Floating-point sums can round slightly for large fractional inputs; use exact decimal or integer minor units for financial totals. The example requires nonnegative additive contributions and rejects an all-zero chart. Production exports should retain category membership, source period and any Other grouping rule so cumulative shares can be reproduced.
Common Mistakes
- Using overlapping cause tags while claiming the bars count unique incidents.
- Removing the long tail before calculating percentages.
- Treating an eighty-percent crossing as a universal law.
- Leaving the two axes unlabeled or suppressing the all-zero state.
Validation drill
Rank 47 maintenance causes by total repair hours, then by incident count. Reconcile both denominators and explain why the first three categories differ between the two charts.
