A few complete, reusable recipes for common needs — copy, adapt, done. Each combines the pieces from earlier modules into a finished chart.
A clean ranked bar chart
s = df.groupby("programme")["package"].mean().sort_values()fig, ax = plt.subplots(figsize=(8, 5))ax.barh(s.index, s.values, color="steelblue")ax.set_title("Average package by programme")ax.spines[["top", "right"]].set_visible(False)for i, v in enumerate(s.values):ax.text(v, i, f" {v:.1f}", va="center") # value labelsfig.tight_layout()
Time series with a moving average
fig, ax = plt.subplots(figsize=(12, 4))ax.plot(ts.index, ts["sales"], alpha=0.3, label="daily")ax.plot(ts.index, ts["sales"].rolling(7).mean(), color="crimson", label="7-day avg")ax.legend(); fig.autofmt_xdate()
Key takeaways
- 01A sorted barh with value labels and hidden spines is a clean ranking chart.
- 02Plot faint raw data plus a bold moving average to show a trend clearly.
- 03Add value labels with a loop of ax.text for at-a-glance reading.
- 04Keep a snippets file of recipes you reuse.
