TinaTz
TinaTz

Reputation: 311

How to plot a combined histogram in python?

I have the following data as example

Names   Static  Dynamic
La  0.1 0.7
Li  0.2 0.02
Sa  0.3 0.044
Pa  0.4 0.444
D   0.7 0.1

my desire is to draw a combined histogram like this one Histogram

any help will be much appreciated

Upvotes: 1

Views: 167

Answers (1)

yatu
yatu

Reputation: 88236

You can pd.melt setting Names as id_vars and use seaborn's sns.catplot:

import pandas as pd
import seaborn as sns

sns.catplot(data=(pd.melt(df, id_vars='Names')
                    .rename(columns={'variable':'x-axis', 'value':'y-axis'})),
            x='x-axis', 
            y='y-axis', 
            hue='Names', 
            kind='bar',
            height=6,
            aspect=1.5)

enter image description here

Upvotes: 2

Related Questions