我发现小提琴图非常有用,我使用python库“ seaborn”。 但是,当应用于正值时,它们几乎总是在下端显示负值。我发现这确实令人误解,尤其是在处理现实数据集时。
seaborn https://seaborn.pydata.org/generated/seaborn.violinplot.html的官方文档中 可以看到带有“ total_bill”和“ tip”的示例, not 不能为负。 但是,小提琴图显示负值。例如,
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中的另一个库?是否可以指定其他内核?
答案 0 :(得分:2)
您可以使用关键字cut=0
将图表限制在数据范围内。如果数据没有负值,这会将小提琴的末尾切为零。使用与您相同的示例,尝试:
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",data=tips, palette="muted", split=True,cut=0)