Python: Matplotlib plot size and colours

25 July 2021

Code to set the default plot size and colour scheme with matplotlib:

import matplotlib.pyplot as plt
import matplotlib as mpl
from cycler import cycler

# centimetres converted to inches, width then height
figsize = (20/2.54, 10/2.54)

# RGB values converted to floats
colours = [
# Example: red, then green, then blue
# These colours will be automatically cycled through when plotting
    (255/255, 0/255, 0/255),
    (0/255, 255/255, 0/255),
    (0/255, 0/255, 255/255)
]

# Set matplotlib defaults
mpl.rcParams['axes.prop_cycle'] = cycler('color', colours)
mpl.rcParams['figure.figsize'] = figsize