【问题标题】:How to plot a combined histogram in python?如何在python中绘制组合直方图?
【发布时间】:2020-10-24 02:54:37
【问题描述】:

我有以下数据作为例子

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

我的愿望是绘制一个像这样的组合直方图

任何帮助将不胜感激

【问题讨论】:

    标签: python pandas matplotlib histogram seaborn


    【解决方案1】:

    您可以将pd.melt 设置为Namesid_vars 并使用seaborn 的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)
    

    【讨论】:

    • 太棒了@yatu,谢谢
    • 我得到了很好的结果,但我正在尝试更改 x 和 y 轴的名称,这给了我错误
    • 怎么做?
    • 更新@christina
    • 非常感谢@yatu,非常有用的答案
    猜你喜欢
    • 2020-01-30
    • 2022-12-18
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多