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)
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With