When to Use a Line Chart
Line charts are best for showing change over time. The connected line emphasises the trend — is data going up, down, or staying flat?
💡
Time on the X-Axis
Line charts almost always have time (hours, days, months, years) on the x-axis. If your x-axis is not time, a bar chart may be a better choice.
Basic Line Chart with matplotlib
import matplotlib.pyplot as plt
months = ["Jan","Feb","Mar","Apr","May","Jun"]
temps = [32, 36, 48, 60, 70, 80]
plt.plot(months, temps)
plt.title("Monthly Temperature")
plt.xlabel("Month")
plt.ylabel("Temp (°F)")
plt.show()
Styling & Multiple Lines
Add colour, markers, and a legend to make charts easier to read. Plot multiple datasets by calling plt.plot() more than once:
plt.plot(months, city1, color="blue", marker="o", label="City A")
plt.plot(months, city2, color="orange", marker="s", label="City B")
plt.legend()
plt.show()
🆕
Markers Matter
Adding marker="o" puts a dot at each data point so viewers can see the exact values, not just the trend line.