Informatics Practices · Ch 4 — Plotting Data using Matplotlib
Colour
Colour
The colour of a plotted line or marker is one of the simplest ways to make a chart more readable or to distinguish between multiple data series. Matplotlib lets you set this using the color parameter inside the plot() function.
You can specify a colour in two ways: using a single-character code (an abbreviation) or the full name of the colour as a string. Both work equally well — the code is just shorter to type.
The textbook provides a standard set of eight colours that are supported by default. Here is the complete list as given in Table 4.4:
| Character Code | Colour Name |
|---|---|
'b' | blue |
'g' | green |
'r' | red |
'c' | cyan |
'm' | magenta |
'y' | yellow |
'k' | black |
'w' | white |
Notice that black uses the code 'k', not 'b' — because 'b' is already reserved for blue. This is a small but important detail to remember for exams. …
| Character | Colour |
|---|---|
| 'b' | blue |
| 'g' | green |
| 'r' | red |
| 'c' | cyan |
| 'm' | magenta |
| 'y' | yellow |