Search code examples
pythonpandasgroup-byseaborn

seaborn barplot of grouped data


This is my dataset:

dataset

I'd like to use seaborn to plot each column, just like pandas would do by default:

plot

Any clue? Thanks in advance


Solution

  • You can first stack the data, and then use sns.barplot with hue:

    stacks = df.stack().reset_index()
    
    plt.figure(figsize=(10,10))
    sns.barplot(x='level_1', y=0, data=stacks, hue='cat')
    plt.show()
    

    Output:

    enter image description here