Understand the idea
A line connects measurements along an ordered axis such as time. Decide whether repeated times represent raw observations or a summary.
A small example
At times 1, 2, 3 with sales 4, 7, 5, the line follows those values in time order.
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=None, marker="o", ax=ax)
ax.set(title="Daily sales", xlabel="day", ylabel="sales")
fig.tight_layout()
plt.show()What each part does
sns.lineplot- connect observations along x
estimator=None- do not average repeated x
marker="o"- show the observed points
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| day | sales |
|---|---|
| 1 | 12 |
| 2 | 15 |
| 3 | 13 |
| 4 | 18 |
| 5 | 21 |
Your task · Follow
- Plot df's sales over day as a line with observation markers ("o") and no aggregation.
- Chart: title "Daily sales"; x "day"; y "sales".
- Use: lineplot().
Hint
A line implies order; estimator=None preserves observations instead of averaging repeated times.
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=None, marker="o", ax=ax)
ax.set(title="Daily sales", xlabel="day", ylabel="sales")
fig.tight_layout()
plt.show()