Understand the idea
When several rows share an x value, a line can summarize them or follow one repeated measurement series.
A small example
At day 1, replicates A=4 and B=8 have mean 6. Selecting replicate A instead plots its observed value 4.
Follow the code
Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(6, 4))
sns.lineplot(
data=df, x="day", y="sales", estimator="mean", errorbar="sd", marker="o", ax=ax
)
ax.set(title="Daily sales · paired observations", xlabel="day", ylabel="sales")
fig.tight_layout()
plt.show()What each part does
estimator="mean"- one mean for each x
errorbar="sd"- spread, not a confidence interval
Other choices for later exercises
estimator=None- retain raw values
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| day | sales | replicate |
|---|---|---|
| 1 | 12 | A |
| 1 | 14 | B |
| 2 | 16 | A |
| 2 | 18 | B |
| 3 | 14 | A |
| 3 | 16 | B |
| 4 | 20 | A |
| 4 | 22 | B |
Your task · Follow
- Using df's paired measurements, plot mean sales at each day, with one-standard-deviation error bands and "o" markers.
- Chart: title "Daily sales · paired observations"; x "day"; y "sales".
- Use: lineplot().
Hint
Repeated times are aggregated when estimator is mean; the SD band shows within-time spread.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
import matplotlib.pyplot as plt
import seaborn as sns
fig, ax = plt.subplots(figsize=(6, 4))
sns.lineplot(
data=df, x="day", y="sales", estimator="mean", errorbar="sd", marker="o", ax=ax
)
ax.set(title="Daily sales · paired observations", xlabel="day", ylabel="sales")
fig.tight_layout()
plt.show()Optional stretch
Use estimator=None and errorbar=None. Why do repeated x values now have several y values?