Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
~\Anaconda3\lib\site-packages\matplotlib\colors.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)
like image 761
dhruv bhardwaj Avatar asked Jun 11 '18 16:06

dhruv bhardwaj


1 Answers

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 matplotlib.

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()
like image 182
Shayan Shafiq Avatar answered Sep 18 '22 05:09

Shayan Shafiq