Colour is Matplotlib's most powerful — and most misused — channel. You can specify it many ways, and using it deliberately is what separates a clear chart from a confusing one.
Specifying colours
ax.plot(x, y, color="crimson") # named CSS colourax.plot(x, y, color="#2563EB") # hexax.plot(x, y, color="C0") # the Nth colour in the cycleax.plot(x, y, color=(0.1, 0.2, 0.5)) # RGB tupleax.plot(x, y, color="tab:blue", alpha=0.7) # tableau palette + transparency
The colour cycle
When you don't specify a colour, Matplotlib walks a default cycle (C0, C1, C2…), so successive lines get distinct colours automatically. That's why two ax.plot calls look different without any effort.
Key takeaways
- 01Colours can be named, hex, RGB tuples, "CN" cycle refs, or "tab:" palette names.
- 02Without a colour, Matplotlib cycles C0, C1, C2… so lines differ automatically.
- 03Use colour to encode meaning, not for decoration.
- 04Prefer colour-blind-safe palettes like tab10 and viridis.
