简体   繁体   中英

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直方图

any help will be much appreciated

You can pd.melt setting Names as id_vars and use seaborn'ssns.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)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM