Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I noticed when you plot that the first line is blue, then green, then red, and so on.

Is there some way to access this list of colours? I've seen a million posts on how to change the colour cycle or access the iterator, but not on how to just get the list of colours that matplotlib cycles through by default.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

In matplotlib versions >= 1.5, you can print the rcParam called axes.prop_cycle:

print(plt.rcParams['axes.prop_cycle'].by_key()['color'])

# [u'#1f77b4', u'#ff7f0e', u'#2ca02c', u'#d62728', u'#9467bd', u'#8c564b', u'#e377c2', u'#7f7f7f', u'#bcbd22', u'#17becf']

Or equivalently, in python2:

print plt.rcParams['axes.prop_cycle'].by_key()['color']

In versions < 1.5, this was called color_cycle:

print plt.rcParams['axes.color_cycle']

# [u'b', u'g', u'r', u'c', u'm', u'y', u'k']

Note that the default color cycle changed in version 2.0.0 http://matplotlib.org/users/dflt_style_changes.html#colors-in-default-property-cycle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...