如何用来自不同列的分组数据并排绘制箱线图

问题描述

我想将数据显示为与两个数值列相对应的两个类别列的并排方框图。

这是我的尝试

# create a list of our conditions
conditions_BPXSY1 = [
    (da['BPXSY1'] < 125),(da['BPXSY1'] >= 125) & (da['BPXSY1'] <= 174),(da['BPXSY1'] > 175)
    ]
conditions_BPXSY2 = [
    (da['BPXSY2'] < 125),(da['BPXSY2'] >= 125) & (da['BPXSY2'] <= 174),(da['BPXSY2'] > 175)
    ]

# create a list of the values we want to assign for each condition
values = ['< 125 mm Hg','125 – 174 mm Hg','175+ mm Hg']

# create a new column and use np.select to assign values to it using our lists as arguments
#da.dropna(inplace=True)
da['BPXSY1x'] = np.select(conditions_BPXSY1,values)
da['BPXSY2x'] = np.select(conditions_BPXSY2,values)

f,axes = plt.subplots(1,2,figsize=(13,6))
sns.boxplot(x="BPXSY1x",y="BPXSY1",data=da,order=['< 125 mm Hg','175+ mm Hg'],orient='v',ax=axes[0])
sns.boxplot(x="BPXSY2x",y="BPXSY2",ax=axes[1])

这是结果:

enter image description here

但是,我希望得到的结果看起来像J是BPXSY1,R是BPXSY2(当然,我没有S)

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)