在单个图中,所有列的箱线图被 "label" 列分割

In a single figure, boxplot of all columns split by a "label" column

查看 boxplot API page,我想要看起来像以下内容的组合:

>>> iris = sns.load_dataset("iris")
>>> ax = sns.boxplot(data=iris, orient="h", palette="Set2")

除非我希望它被一个包含特定标签的列拆分,类似于以下示例中 hue 参数所实现的效果:

ax = sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips, palette="Set3")

此示例仅在定义 xy 时有效,但对于我想要实现的目标,我希望 x 基本上是数据框中的每一列(标签除外) ,显然)和 y 是频率,类似于第一个示例中显示的内容。如果用 seaborn 无法实现,我愿意为 python.

尝试一些其他的可视化库

你需要"unstack"或"melt"这样的数据,一切都是值,而不是变量(长格式而不是宽格式)。

这是它的样子:

iris_xtab = seaborn.load_dataset("iris")
iris_long = pandas.melt(iris, id_vars='species')
seaborn.boxplot(x='species', y='value', hue='variable', data=iris_long)

或者将物种值省略为 x(您必须按照之前的建议分配一个虚拟值

ax = seaborn.boxplot(x='pos', y='value', hue='variable', 
                     data=iris_long.assign(pos=1))