Skip to content

Informatics Practices · Ch 4 — Plotting Data using Matplotlib

Colour

4.3.2

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 CodeColour Name
'b'blue
'g'green
'r'red
'c'cyan
'm'magenta
'y'yellow
'k'black
'w'white
Note

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. …

Table 4.4Colour abbreviations for plotting
CharacterColour
'b'blue
'g'green
'r'red
'c'cyan
'm'magenta
'y'yellow