Skip to content

04-03: City Statistics — Matplotlib Bar Charts

Python: Data Analytics

View the live site — ijk37.com

Project 03

Home  |  All Projects  |  Notes  |  Exercises  |  Quiz Hub

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

pip install matplotlib numpy

How to Run

python main.py

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