【发布时间】:2021-01-20 03:57:59
【问题描述】:
我想将我的数据可视化为对应于两个数值列的两个分类列上的并排箱线图。
这是我的尝试
# 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', '125 – 174 mm Hg', '175+ mm Hg'], orient='v' , ax=axes[0])
sns.boxplot(x="BPXSY2x", y="BPXSY2", data=da, order=['< 125 mm Hg', '125 – 174 mm Hg', '175+ mm Hg'], orient='v' , ax=axes[1])
结果如下:
但是,我希望 J 是 BPXSY1,R 是 BPXSY2 的结果(当然,我没有 S)
【问题讨论】:
标签: python pandas seaborn boxplot categorical-data