Seaborn lineplot: distinguish the mean and confidence interval from raw data
When several observations share an x value, Seaborn lineplot draws their mean by default and shows a 95% bootstrap confidence interval for that mean estimate. The band is neither the range of individual observations nor their standard deviation. This guide uses fictional weekly orders from four branches to explain what the default aggregation shows and how to switch to data spread or branch-level trajectories. The official Seaborn 0.13.2 documentation was checked on 2026-11-18.
Seaborn lineplot: distinguish the mean and confidence interval from raw data
When several observations share an x value, Seaborn lineplot draws their mean by default and shows a 95% bootstrap confidence interval for that mean estimate. The band is neither the range of individual observations nor their standard deviation. This guide uses fictional weekly orders from four branches to explain what the default aggregation shows and how to switch to data spread or branch-level trajectories. The official Seaborn 0.13.2 documentation was checked on 2026-11-18.
Check what one row represents
Seaborn's dataset-oriented functions work well with long-form tables: one column per variable and one row per observation. Here, each row represents one branch in one week. All values are invented for instruction, not business measurements.
The following code draws the weekly mean and a 95% confidence band for that mean. The Python environment needs Seaborn, pandas and Matplotlib installed:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.DataFrame({
"branch": ["A", "A", "A", "A",
"B", "B", "B", "B",
"C", "C", "C", "C",
"D", "D", "D", "D"],
"week": [1, 2, 3, 4] * 4,
"orders": [100, 120, 130, 150,
110, 115, 140, 145,
90, 125, 120, 155,
105, 130, 135, 160],
})
ax = sns.lineplot(
data=data,
x="week",
y="orders",
estimator="mean",
errorbar=("ci", 95),
n_boot=1000,
seed=42,
)
ax.set(
title="Weekly orders by branch (illustrative data)",
xlabel="Week",
ylabel="Orders (illustrative)",
)
plt.show()In a notebook with Matplotlib display mode enabled, the figure may appear after the cell runs. In a regular script, call plt.show() to open a window. The plot has weeks 1–4 on x and mean orders on y, with an interval around each estimate. The seed makes bootstrap sampling reproducible; n_boot sets the resample count. This example has not been executed.
What does the default interval mean?
When multiple rows have the same x value, lineplot aggregates y using estimator. The default estimator is the mean, and the default errorbar is a 95% bootstrap confidence interval for that mean. Bootstrapping repeatedly samples observations with replacement and recomputes the estimate. The band describes uncertainty in the estimated mean; it is not the minimum-to-maximum range of branch orders or the range containing 95% of raw observations.
The interval depends on the sample and the assumptions behind the inference. With only four branches, or with dependent observations, do not treat the band as a precise measure of uncertainty. More bootstrap repetitions alone cannot correct sampling bias or a poor observation design.
| Question | Seaborn setting | What it displays |
|---|---|---|
| Mean and uncertainty in its estimate | estimator="mean", errorbar=("ci", 95) | Mean line and bootstrap confidence interval |
| Observed spread around the mean | errorbar="sd" | One standard deviation on either side |
| Middle 95% of observed values | errorbar="pi" | Sample 2.5th to 97.5th percentiles |
| Summary line without an interval | errorbar=None | Aggregated line only |
| Separate branch trajectories | hue="branch", estimator=None | One line per branch, without aggregation |
A mean line can hide the raw distribution and outliers. It helps when the question concerns an average or a trend, but inspect the observations too when spread matters. To see each branch, set hue to branch and estimator to None. Many branches can make the legend hard to read; consider facets or a concise data summary.
To draw the four branch lines instead of the mean and interval:
sns.lineplot(data=data, x="week", y="orders", hue="branch", estimator=None)Verify the result and fix common problems
**Fewer lines than expected:** repeated rows at each week may have been averaged. Use hue="branch" and estimator=None for individual branch paths.
**The band does not include the raw minimum and maximum:** the default is an interval for the estimated mean, not the observed range. Choose sd or pi if that matches the question.
**The band is wide or unstable:** check the independent observations per week, missing values and repeated-measure structure. A fixed seed reproduces bootstrap randomness but does not remove data limitations.
**Weeks appear out of order:** keep week numeric, or define an explicit order for categorical values. lineplot sorts x by default.
**Seaborn cannot be imported:** run python -m pip install -U seaborn pandas matplotlib in the same Python environment that runs the script.
**No plot window appears:** check notebook display mode; in a regular script call plt.show(). On a headless server, save the figure with Matplotlib instead.
Sources
[Seaborn documentation: Introduction](https://seaborn.pydata.org/tutorial/introduction.html)
[Seaborn documentation: Visualizing statistical relationships](https://seaborn.pydata.org/tutorial/relational.html)
[Seaborn API: lineplot](https://seaborn.pydata.org/generated/seaborn.lineplot.html)
[Seaborn documentation: Statistical estimation and error bars](https://seaborn.pydata.org/tutorial/error_bars.html)
[Seaborn documentation: Data structures](https://seaborn.pydata.org/tutorial/data_structure.html)
[Seaborn documentation: Installing and getting started](https://seaborn.pydata.org/installing.html)