Module 5: Charts with matplotlib · 10 min
Your first chart
import matplotlib.pyplot as plt
cities = ["Lahore", "Karachi", "Multan"]
sales = [550, 400, 150]
plt.bar(cities, sales)
plt.title("Sales by city")
plt.xlabel("City")
plt.ylabel("Sales (units)")
plt.savefig("sales.png") # save to a file
plt.show() # or show on screen
Always add a title and axis labels. A chart without them makes the reader guess.
With pandas you can plot directly from a column: df["sales"].plot(kind="bar").