【问题标题】:Seaborn boxplot with dataframe containting quantiles带有包含分位数的数据框的 Seaborn 箱线图
【发布时间】:2021-10-07 11:38:16
【问题描述】:

如果我有一个已知分位数的数据框,我可以让 Seaborn 箱线图显示每个百分位数上的小菱形吗?

test = pd.DataFrame(
    {
        "id": ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
        "q": [0.16, 0.5, 0.84, 0.16, 0.5, 0.84, 0.16, 0.5, 0.84],
        "value": [0.2, 0.56, 0.84, 0.14, np.nan, 0.78, 0.125, 0.4, 0.62],
    }
)

display(test)
sns.boxplot(data=test, x="value", y="id")

【问题讨论】:

    标签: python matplotlib seaborn percentile


    【解决方案1】:

    也许这对你有帮助:

    import seaborn as sns
    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    
    
    test = pd.DataFrame(
        {
            "id": ["A", "A", "A", "B", "B", "B", "C", "C", "C"],
            "q": [0.16, 0.5, 0.84, 0.16, 0.5, 0.84, 0.16, 0.5, 0.84],
            "value": [0.2, 0.56, 0.84, 0.14, np.nan, 0.78, 0.125, 0.4, 0.62],
        }
    )
    
    display(test)
    g = sns.boxplot(data=test, x="value", y="id")
    
        
    for index, row in test.iterrows():
        if(row['id']=='A'):
            g.plot((row['q']), (row['id']), 'o', color='y')
        if(row['id']=='B'):
            g.plot((row['q']), (row['id']), 'o', color='b')        
        if(row['id']=='C'):
            g.plot((row['q']), (row['id']), 'o', color='r')
            
    plt.show()
    

    输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-05
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 2021-04-18
      • 2016-12-18
      • 2018-09-08
      相关资源
      最近更新 更多