Combine a density silhouette, quartile summary and stable raw points without hiding unequal group sizes or bandwidth choices.
Raincloud plots: show the estimate, summary and records together
Three layers answer three questions
A raincloud plot places a distribution estimate, a compact summary and individual observations beside one another for each group. The density shape helps locate concentrations, the quartiles orient a comparison, and raw points reveal outliers, ties and sample size. None of the layers should be allowed to contradict another through a hidden filter. Use the same eligible records for all three, then display the count near each group. For service latency, a broad-looking density may come from seven observations while a narrow-looking one may come from hundreds; if both are normalized to area one, shape width is not a record count. Keep a shared value axis and state whether the density is normalized within each group or scaled to count. A simple box or violin plot may be clearer when there are many groups. Beeswarm points are a better raw layer when exact overlaps matter.
Freeze smoothing and value bounds
The cloud is a model of a distribution, not a trace of every observation. A Gaussian kernel density estimate spreads each record over nearby values according to a bandwidth. Too little smoothing turns each value into its own bump; too much erases shoulders or separated clusters. For a comparison, use one declared bandwidth in the measured unit and one common grid. If groups are measured on different units, convert them before plotting or keep separate panels. The example below uses a fixed bandwidth of two minutes and a grid spanning every observed value plus three bandwidths on each side. That avoids trimming the visible tails differently by group. It also keeps the half-violin widths as within-group density, so their maximum heights should not be read as a sample-size comparison. Histogram density offers another check on smoothing.
Keep raw points stable and quartile policy explicit
A little horizontal jitter separates identical or nearly identical values, but jitter must not alter the measured axis. The code derives a stable display offset from each record identifier, so refreshing a dashboard does not make the same observation jump to a random place. It does not guarantee that all points are collision-free; densely repeated values may still need a beeswarm algorithm or a count label. The quartiles use one named calculation policy, and the same policy must be used for every group and exported summary. A whisker rule should also be named if whiskers are drawn. The worked ledger omits them rather than letting a plotting library silently choose. When records are paired across groups, a raincloud can conceal that relationship; a connected paired display is more appropriate for the primary comparison. Paired change charts preserve identity.
Choose a view that survives small screens
A cloud, box and points can become three cramped marks on a phone. Keep the value axis labeled, leave room for group names, and offer a table with count, median, quartiles and every raw value when feasible. A screen reader should not announce a hundred decorative cloud coordinates; it needs the group summary and a path to the underlying records. If a small group contains only a handful of observations, the smoothed cloud can imply more certainty than the data warrant. Show the points and summary first, and either omit the density or label it as exploratory. If a record disappears under a filter, recompute all three layers from the same filtered population. Small-sample display, accessible alternatives and shared facets help keep the comparison honest.
Worked contract
from hashlib import blake2s
from math import exp, isfinite, pi, sqrt
from statistics import median, quantiles
def prepare_latency_raincloud(groups, bandwidth_minutes, grid_size=41):
if (not groups or not isinstance(bandwidth_minutes, (int, float)) or
isinstance(bandwidth_minutes, bool) or not isfinite(bandwidth_minutes) or
bandwidth_minutes <= 0 or not isinstance(grid_size, int) or
isinstance(grid_size, bool) or grid_size < 3):
raise ValueError("invalid groups, bandwidth or grid size")
all_minutes = []
for group_name, records in groups.items():
if not isinstance(group_name, str) or not group_name.strip() or len(records) < 4:
raise ValueError("each named group needs at least four records")
record_ids = [record_id for record_id, _ in records]
if (len(set(record_ids)) != len(record_ids) or
any(not isinstance(record_id, str) or not record_id.strip()
for record_id in record_ids)):
raise ValueError("record IDs must be unique within each group")
for _, minutes in records:
if (not isinstance(minutes, (int, float)) or isinstance(minutes, bool) or
not isfinite(minutes) or minutes < 0):
raise ValueError("latencies must be finite nonnegative minutes")
all_minutes.append(minutes)
lower = min(all_minutes) - 3 * bandwidth_minutes
upper = max(all_minutes) + 3 * bandwidth_minutes
grid = [lower + (upper - lower) * index / (grid_size - 1)
for index in range(grid_size)]
prepared = {}
for group_name, records in groups.items():
minutes = sorted(value for _, value in records)
first_quartile, _, third_quartile = quantiles(minutes, n=4, method="inclusive")
density = [sum(exp(-0.5 * ((position - value) / bandwidth_minutes) ** 2)
for value in minutes) /
(len(minutes) * bandwidth_minutes * sqrt(2 * pi))
for position in grid]
points = []
for record_id, value in records:
digest = blake2s(record_id.encode(), digest_size=4).digest()
display_offset = (int.from_bytes(digest, "big") / 2**32 - 0.5) * 0.2
points.append((record_id, value, display_offset))
prepared[group_name] = {"count": len(minutes), "median": median(minutes),
"quartiles": (first_quartile, third_quartile),
"density": density, "points": points}
return grid, prepared
queue_minutes = {
"north": [("N-41", 12), ("N-42", 13), ("N-43", 14), ("N-44", 14),
("N-45", 15), ("N-46", 16), ("N-47", 27)],
"south": [("S-51", 11), ("S-52", 12), ("S-53", 12), ("S-54", 13),
("S-55", 18), ("S-56", 19), ("S-57", 20), ("S-58", 21)],
}
grid, clouds = prepare_latency_raincloud(queue_minutes, bandwidth_minutes=2)
assert len(grid) == 41 and clouds["north"]["median"] == 14
assert clouds["south"]["median"] == 15.5
assert len(clouds["north"]["points"]) == 7Performance and operating cost
Let N be the total observations across G groups and M the number of shared grid positions. Sorting within groups costs at most O(N log N); direct Gaussian density evaluation costs O(MN). Storage is O(N + GM) for raw points and density arrays. The two queue groups contain seven and eight recorded durations. North's median is 14 minutes; south's is 15.5. Both clouds use the same two-minute bandwidth and common value grid. Their density curves are normalized within group, so a taller peak does not mean more records. The stable identifier-derived offset affects only a point's cross-axis display position; the latency value and quartile calculation remain unchanged. For very large N, choose a tested KDE implementation or a binned approximation, and state the approximation in the export.
Common Mistakes
- Letting each group or refresh pick its own bandwidth and then comparing the apparent number of modes.
- Interpreting equal-area density height as a sample count.
- Moving raw points along the measured value axis while calling it harmless jitter.
- Computing the cloud, quartiles and raw points from different filtered subsets.
- Hiding small group sizes behind a smooth cloud or omitting the quartile calculation policy.
Validation drill
Compare two service queues with 47 and 83 eligible requests. Use one value domain and one predeclared bandwidth, keep every raw duration tied to a stable request ID, label both sample sizes, and check whether an apparent second peak remains after viewing the points and a binned histogram.
