04-03: City Statistics — Matplotlib Bar Charts¶
Produces a 2×2 subplot figure showing Bangladesh city statistics: population (vertical bar), area (horizontal bar), population density (colour-coded), and literacy rate (with a reference line). Saved as city_statistics.png.
Topics covered: plt.subplots() · ax.bar() · ax.barh() · ax.text() (annotations) · ax.axvline() · colour maps · plt.tight_layout() · plt.savefig()
Difficulty: ⭐⭐ Intermediate
Requirements¶
How to Run¶
Output: city_statistics.png
Key Concepts Practised¶
| Concept | Where used |
|---|---|
plt.subplots(2, 2) |
2×2 grid layout |
ax.bar() / ax.barh() |
Vertical / horizontal bars |
ax.text() on bars |
Data labels |
plt.cm.Blues(linspace) |
Colour gradient |
| Conditional colours | Red if density > 40k |
ax.axvline() |
Reference line at 60% |
plt.savefig(dpi=150) |
Export to PNG |