I've defined a custom color cycler in a text file, and am invoking it via plt.style.context()
. The cycle I've defined has 12 colors. When annotating the plot, if I try to access my custom cycler colors using color strings, 'C0'
through 'C9'
work but 'C10'
throws ValueError: Invalid RGBA argument: 'C10'
. All 12 values are definitely in there. Contents of style file style.yaml
:
axes.prop_cycle : cycler('color', ['332288', 'CC6677', 'DDCC77', '117733', '88CCEE', 'AA4499', '44AA99', '999933', '882255', '661100', '6699CC', 'AA4466'])
Test script:
import numpy as np
import matplotlib.pyplot as plt
data = np.c_[np.zeros(13), np.arange(13)].T
labels = list('abcdefghijklm')
with plt.style.context('style.yaml'):
# just to prove that the colors are loading correctly:
cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']
print('{} colors: {}'.format(len(cycle), cycle))
# now the actual plotting:
fig, ax = plt.subplots()
ax.plot(data)
for ix in range(data.shape[1]):
ax.text(x=1, y=data[1, ix], s=labels[ix], color='C{}'.format(ix))
The result (notwithstanding the ValueError
that stops it plotting after 10 labels) is that the lines follow my custom cycler colors, but the text labels use the matplotlib default cycler colors (see screenshot). How can I get the text to appear using the custom cycler colors defined in the external YAML file?