Python的小提琴正数值图 [英] Violin plot for positive values with python

查看:421
本文介绍了Python的小提琴正数值图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现小提琴图非常有用,我使用python库"seaborn". 但是,当应用于正值时,它们几乎总是在下端显示负值.我发现这确实令人误解,尤其是在处理现实数据集时.

I find violin plots very informative and useful, I use python library 'seaborn'. However, when applied to positive values, they nearly always show negative values at the lower end. I find this really misleading, especially when working with real-life datasets.

在seaborn的官方文档中 https://seaborn.pydata.org/genic/seaborn.violinplot.html 可以看到带有"total_bill"和"tip"的示例,这些示例 not 不能为负. 但是,小提琴图显示为负值.例如,

In the official documentation of seaborn https://seaborn.pydata.org/generated/seaborn.violinplot.html one can see examples with "total_bill" and "tip" which can not be negative. The violin plots show negative values, however. For example,

import seaborn as sns
sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",data=tips, palette="muted", split=True)

我确实知道,那些负值来自高斯核.因此,我的问题是:有什么办法可以解决这个问题? python中的另一个库?是否可以指定其他内核?

I do understand, that those negative values come from gaussian kernels. My question is, therefore: is there any way to solve this problem? Another library in python? Possibility to specify a different kernel?

推荐答案

您可以使用关键字cut=0将绘图限制在数据范围内.如果数据没有负值,这会将小提琴的末尾切为零.使用与您相同的示例,尝试:

You can use the keyword cut=0 to limit your plot to the data range. If the data doesn't have negative values, this will chop the end of the violin to zero. Using the same example as you, try:

ax = sns.violinplot(x="day", y="total_bill", hue="smoker",data=tips, palette="muted", split=True,cut=0)

这篇关于Python的小提琴正数值图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆