看着箱线图 API 页面 http://seaborn.pydata.org/generated/seaborn.boxplot.html#seaborn.boxplot,我想要看起来像这样的组合的东西:
>>> 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")
此示例仅在以下情况下有效x
and y
已定义,但对于我想要实现的目标x
基本上是我的数据框中的每一列(显然除了标签)并且y
为频率,类似于第一个示例中所示的内容。如果用seaborn无法实现,我愿意尝试其他一些Python可视化库。
您需要“拆开”或“融化”数据,这样一切都是值,而不是变量(长格式而不是宽格式)。
看起来是这样的:
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))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)