Display colors by color values ​​in pandas dataframe

I have a dataframe that looks like this.

raw_data = {'Enum': ['E330','E322','E124','E500'],'Count': [234, 122, 765, 433],
'Colors':['red','blue','green','yellow']}

additives_count = pd.DataFrame(raw_data)

I want to plot a histogram and I used the code below.

ax = additives_count.plot(kind='barh',colors=additives_count['Colors'])

The only problem is that I cannot make the corresponding colors in Enum. I got my bar plot, but only 1 color. So, for example, my plot should have E330, portrayed as red, E322 blue, E124 green, and E500 - yellow. How can i achieve this?

Please note that this is just a very small subset of my data. I have 30 lines to build, but I believe that you get the gist of what I'm trying to achieve. Any help would be greatly appreciated.

Thank!

+4
source share
2 answers

x y :

ax = additives_count.plot(x="Enum",y="Count",kind='barh',color=additives_count['Colors'])

, colors , color. :

enter image description here

+2

, x-axis, - y-axis.

additives_count.plot(x='Enum', y='Count',kind='barh',color=additives_count['Colors'])

. enter image description here

+4

Source: https://habr.com/ru/post/1694765/


All Articles