11  Data Visualization

11.1 A basic line chart

import matplotlib.pyplot as plt

years = [2021, 2022, 2023, 2024, 2025]
values = [12, 15, 14, 19, 23]

plt.plot(years, values, marker="o")
plt.title("Value by year")
plt.xlabel("Year")
plt.ylabel("Value")
plt.show()

11.2 A bar chart

cities = ["A", "B", "C"]
values = [20, 35, 28]

plt.bar(cities, values)
plt.title("Value by city")
plt.xlabel("City")
plt.ylabel("Value")
plt.show()

11.3 Things to remember

  • A chart should answer a specific question.
  • Label axes and units.
  • Avoid unnecessary visual elements.
  • Inspect the underlying data before plotting it.