Using df, how did visits change over days 2 through 5 inclusive?
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
Your requirements
- Connect those ordered observations with a line and markers, without aggregation.
- Chart: title "Daily site visits"; x "day"; y "visits".
Your inputs
| day | visits |
|---|---|
| 1 | 40 |
| 2 | 52 |
| 3 | 47 |
| 4 | 60 |
| 5 | 68 |
Remember 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.
| Code or choice | Meaning |
|---|---|
estimator=None | Keep raw observations rather than averaging values at the same x. |
marker="o" | Show a circular marker at each plotted observation. |
sort=True (default) | Seaborn sorts x before connecting. Matplotlib ax.plot connects in the supplied order. |
Hint
An ordered time question supports connecting neighboring observations.
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))
selected = df[(df["day"] >= 2) & (df["day"] <= 5)]
ax.plot(selected["day"], selected["visits"], marker="o")
ax.set(title="Daily site visits", xlabel="day", ylabel="visits")
fig.tight_layout()
plt.show()