Ravindra BagaleCourses & study guides मराठी Track your progress

13. Visualization with matplotlib

Data Science

13.2 Line and Hist

# Fictional daily orders in Pune around Diwali
days = list(range(1, 11))
orders = [180, 190, 210, 250, 900, 880, 400, 220, 200, 190]

fig, ax = plt.subplots()
ax.plot(days, orders, marker="o")
ax.set_title("Pune daily orders (fictional) — Diwali spike")
ax.set_xlabel("Day of October 2026")
ax.set_ylabel("Orders")
ax.axhline(500, linestyle="--", label="Spike threshold")
ax.legend()
plt.show()
mins = [9, 12, 11, 14, 18, 10, 8, 13, 16, 17, 11, 9]
fig, ax = plt.subplots()
ax.hist(mins, bins=5)
ax.set_title("Delivery minutes distribution (fictional sample)")
ax.set_xlabel("Minutes")
ax.set_ylabel("Count")
plt.show()

Steps in Jupyter

  1. Plot the city GMV bar chart.
  2. Rotate x labels so Sambhaji Nagar is readable.
  3. Plot the Diwali line chart with a threshold line.
  4. Save: fig.savefig("figures/pune_diwali.png", dpi=120).

What you should see. Clear spike on days 5–6; PNG appears in figures/.

Ravindra Bagale's Tip

Save your chart with fig.savefig("figures/pune_diwali.png", dpi=120) instead of taking a screenshot, because the same code can make the same clear image again. The safest habit is to call savefig before plt.show() in the same cell. Create the figures folder first, because savefig does not create folders and stops with a FileNotFoundError.