【问题标题】:Hierarchical Grouped Boxplot,分层分组箱线图,
【发布时间】:2021-08-28 11:24:15
【问题描述】:

我的数据看起来像:

    engages_telehealth  knockout_tox    pcc  variable    value
0                 True          True   True    health   135.50
1                 True          True   True  admitted  3443.25
2                 True          True  False    health   136.50
3                 True          True  False  admitted  3444.45
4                 True         False   True    health   115.50
5                 True         False   True  admitted  3640.80
6                 True         False  False    health   117.75
7                 True         False  False  admitted  3615.60
8                False          True   True    health   137.00
9                False          True   True  admitted  3314.90
10               False          True  False    health   136.00
11               False          True  False  admitted  3320.40
12               False         False   True    health   115.00
13               False         False   True  admitted  3334.25
14               False         False  False    health   115.00
15               False         False  False  admitted  3363.25

我想制作一个类似于下图的层次聚类箱线图,这是描述生物学中多种条件的某种标准方式。

分层图的其他 SO 问题(thisthis)可能有三层,但这些是集群而不是独立条件,我的条件是布尔而不是数字。

我试过猫图:

  print(df_graph)

fig = plt.figure()
ax=fig.add_subplot(111)

sns.catplot(data=df_graph,x='variable',y='value',col=[ck1,ck2], kind='bar', ax=ax)
plt.show() 

但是,col 参数只接受一个字符串,我不想创建一个FacetGrid,因为我正在准备的文档中没有空间。

【问题讨论】:

    标签: python matplotlib seaborn data-visualization graphing


    【解决方案1】:

    这应该让您非常接近。您不会看到任何错误栏,因为每个类别的记录不超过一条。如果你这样做,他们就会出现。

    import seaborn as sns
    sns.set(rc={'figure.figsize':(16,9)})
    sns.set_context('talk')
    
    
    df = df.replace({True:'+', False:'-'})
    df['cat'] = 'TELE' + df['engages_telehealth']+'\nTOX '+df['knockout_tox']+'\nPCC '+df['pcc']
    
    
    sns.barplot(data=df, x='cat', y='value', hue='variable')
    

    输出

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2016-09-14
      • 2013-05-11
      • 2021-03-08
      • 1970-01-01
      • 2014-06-07
      • 2020-08-03
      • 2019-04-29
      • 2016-01-26
      相关资源
      最近更新 更多