Is there a simple way to increment the matplotlib color cycle without digging into axes internals?
When plotting interactively a common pattern I use is:
There are several colour schemes available in Pyplot. You can read more on the matplotlib tutorial Specifying Colors.
From these docs:
a "CN" color spec, i.e. 'C' followed by a number, which is an index into the
default property cycle (matplotlib.rcParams['axes.prop_cycle']); the indexing
is intended to occur at rendering time, and defaults to black if the cycle
does not include color.
You can cycle through the colour scheme as follows:
fig, ax = plt.subplots()
# Import Python cycling library
from itertools import cycle
# Create a colour code cycler e.g. 'C0', 'C1', etc.
colour_codes = map('C{}'.format, cycle(range(10)))
# Iterate over series, cycling coloour codes
for y in my_data:
ax.plot(x, y, color=next(color_codes))
This could be improved by cycling over matplotlib.rcParams['axes.prop_cycle']
directly.