Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib 1.5 usage of axes.prop_cycle

axes.color_cycle is deprecated in Matplotlib 1.5. However its usage was quite straightforward: we could easily grab a specific color by:

plt.rcParams['axes.color_cycle'][color_number]

axes.prop_cycle does not support this syntax:

ValueError: Can only use slices with Cycler.__getitem__

And cycler doc is not very detailed http://matplotlib.org/cycler/

So I don't know how I can get a specific color from prop_cycle. Any idea? Thanks

like image 945
Arthur Avatar asked Dec 13 '15 02:12

Arthur


2 Answers

To get the value you want:

list(mpl.rcParams['axes.prop_cycle'])[1]['color'])

There is an open PR to add a by_key method to Cycler objects so this will eventually be

mpl.rcParams['axes.prop_cycle'].by_key()['color'][1]

There are also some discussions about mapping the color 'c1' to the first color in the prop_cycle, but that has not been implemented yet.

I am the main author of the cycler docs, what additional detail would you want to see there?

like image 167
tacaswell Avatar answered Nov 05 '22 10:11

tacaswell


colors = [color['color'] for color in list(mpl.rcParams['axes.prop_cycle'])]
colors[1]

is a way to restore the old use. First line returns a 2-D array of colors.

like image 25
pheon Avatar answered Nov 05 '22 10:11

pheon