Skip to course content
Free data visualization course

Data Visualization and Dashboard Storytelling

Unit 10.03: Statistical defaults you should not accept silently

Seaborn's statistical defaults are reasonable, unstated, and usually misread.

The bar is a mean and the whisker is a confidence interval

A grouped bar chart produced by one call, with its defaults spelled out.

The code names what was computed.

import matplotlib
matplotlib.use("Agg")
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

rng = np.random.default_rng(0)
df = pd.DataFrame({"group": ["A"] * 30 + ["B"] * 30,
                   "value": np.concatenate([rng.normal(10, 3, 30),
                                            rng.normal(12, 3, 30)])})

ax = sns.barplot(data=df, x="group", y="value")
print("sns.barplot defaults:")
print("   bar height     = the MEAN, not the sum or the median")
print("   the error bar  = a 95% bootstrap confidence interval")
print(f"   bars drawn     = {len([p for p in ax.patches])}")
plt.close("all")

print("""
Both defaults are reasonable and neither is stated on the chart. A reader
seeing a bar chart usually assumes totals, and a reader seeing a whisker
usually cannot say what it represents.

Say so in the axis label -- "mean value (95% CI)" -- or choose the statistic
explicitly.
""")

A reader seeing a bar chart usually assumes totals. A reader seeing a whisker usually cannot say what it represents - a standard deviation, a standard error, a confidence interval, or a range.

Both are reasonable defaults and neither appears anywhere on the chart, so the reader is left to assume.

The mistake this prevents

The mistake is using the default and describing the chart as showing totals in the accompanying text. The chart and the commentary then disagree, and the commentary is what people remember.

Takeaway

State the statistic in the axis label - "mean value (95% CI)" - or choose it explicitly. Unstated defaults are read as whatever the reader expects.