The line plot is Matplotlib's default and most-used chart — perfect for anything continuous or ordered, especially trends over time. ax.plot(x, y) connects the points in order.
Drawing lines
ax.plot(x, y) # a simple lineax.plot(x, y, color="crimson", linewidth=2, linestyle="--")ax.plot(x, y, marker="o") # show the data points tooax.plot(x, y1, x, y2) # two lines in one call
When to use it
| Good for | Not for |
|---|---|
| Trends over time | Unordered categories (use bars) |
| Continuous functions | Showing individual points only (use scatter) |
| Comparing a few series | Many overlapping series (gets cluttered) |
Key takeaways
- 01ax.plot(x, y) draws a line connecting points in order — the default chart.
- 02Style with color, linewidth, linestyle and marker.
- 03Best for trends over time and continuous data.
- 04Lines imply order — don't use them for unordered categories.
