python小提琴正值图

时间:2020-01-08 15:50:29

标签: python seaborn visualization data-analysis violin-plot

我发现小提琴图非常有用,我使用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)

enter image description here

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

1 个答案:

答案 0 :(得分:2)

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

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