我发现小提琴图非常有用,我使用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的官方文档中 seaborn.pydata/genic/seaborn.violinplot.html 可以看到带有"total_bill"和"tip"的示例,这些示例 not 不能为负. 但是,小提琴图显示为负值.例如,
In the official documentation of seaborn seaborn.pydata/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的小提琴正数值图
发布评论