Python的小提琴正数值图

编程入门 行业动态 更新时间:2024-10-26 09:19:12
本文介绍了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的官方文档中 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的小提琴正数值图

本文发布于:2023-07-18 08:19:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小提琴   数值   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!