pythonpandasmatplotlib

How can I change the color of a grouped bar plot in Pandas?


I have this plot that you'll agree is not very pretty. Other plots I made so far had some color and grouping to them out of the box.

I tried manually setting the color, but it stays black. What am I doing wrong? Ideally it'd also cluster the same tags together.

df.groupby(['tags_0', 'gender']).count().plot(kind='barh', legend=False, color=['r', 'g', 'b'])

enter image description here


Solution

  • You need to unstack your results:

    df.groupby(['tags_0', 'gender']).gender.count().unstack().plot(kind='barh', legend=False, color=['r', 'g', 'b'])
    

    Chart

    I don't have your data, so just used a value of one for each tag/gender combo.