Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
960 views
in Technique[技术] by (71.8m points)

python - ValueError: Invalid RGBA argument: 'rgbkymc'

train_class = train_df['Class'].value_counts().sortlevel()
my_colors = 'rgbkymc'  #red, green, blue, black, etc.
train_class.plot(kind='bar', color=my_colors)
plt.grid()
plt.show()

I'm getting:

Value Error : Invalid RGBA argument : 'rgbkymc'

I can't get the reason why I'm getting this error as I have checked everything and it seems fine.

Can anyone help me identify the error, please?

KeyError                                  Traceback (most recent call last)
~Anaconda3libsite-packagesmatplotlibcolors.py in to_rgba(c, alpha)
131     try:
--> 132         rgba = _colors_full_map.cache[c, alpha]
133     except (KeyError, TypeError):  # Not in cache, or unhashable.

KeyError: ('rgbkymc', None)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The question needs a slight modification as it would first raise the following error:

```AttributeError: 'Series' object has no attribute 'sortlevel'```

This is because sortlevel is deprecated since version 0.20.0. You should instead use sort_index in its place.

Plus, the letters symbolising the colors in the color parameter of the plot command need to be provided in a list and not in a string. You can read more about it on Specifying Colors on .

Hence, you can use this code:

train_class = train_df['Class'].value_counts().sort_index()
my_colors = ['r', 'g', 'b', 'k', 'y', 'm', 'c']  #red, green, blue, black, 'yellow', 'magenta' & 'cyan'
train_class.plot(kind = 'bar', color = my_colors)
plt.grid()
plt.show()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...