gpt4 book ai didi

python - 使用python绘制正值的 fiddle 图

转载 作者:行者123 更新时间:2023-12-03 23:49:35 24 4
gpt4 key购买 nike

我发现 fiddle 图非常有用且有用,我使用 python 库“seaborn”。
然而,当应用于正值时,它们几乎总是在低端显示负值。我发现这确实具有误导性,尤其是在处理现实生活中的数据集时。

在seaborn的官方文档中https://seaborn.pydata.org/generated/seaborn.violinplot.html
人们可以看到“total_bill”和“tip”不能为负的例子。
然而, fiddle 图显示负值。例如,

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中的另一个库?可以指定不同的内核吗?

最佳答案

您可以使用关键字 cut=0将您的绘图限制在数据范围内。如果数据没有负值,这会将 fiddle 的末端切为零。使用与您相同的示例,尝试:
ax = sns.violinplot(x="day", y="total_bill", hue="smoker",data=tips, palette="muted", split=True,cut=0)

关于python - 使用python绘制正值的 fiddle 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59649413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com