简体   繁体   English

具有常量值数组的Python Seaborn调度

[英]Python Seaborn displot with array of constant values

I have a problem using seaborn.distplot with an array of constant values. 我在将seaborn.distplot与常量值数组一起使用时遇到问题。

import seaborn as sns
sns.distplot([1] * 10)

Returns: 返回值:

ValueError: cannot convert float NaN to integer

-- EDIT: new version of Seaborn (0.6.0) solves the problem -编辑:Seaborn(0.6.0)的新版本解决了该问题

The previous problem happened with seaborn version 0.5.1. 先前的问题发生在seaborn版本0.5.1中。 Solved with version 0.6.0. 用0.6.0版本解决。

Don't use the same value for all items in the data. 请勿对数据中的所有项目使用相同的值。 Because there is no variance between the lower and upper values in the range (or the 1st and 3rd quartiles depending on how the bins are calculated), the bins become undefined ie nan . 由于范围内的下限值和上限值之间没有差异(或第一和第三四分位数取决于bin的计算方式),因此bin变得不确定,即nan This can not be converted to an integer and is the cause of the exception that you see. 无法将其转换为整数,这是您看到异常的原因。 Possibly that is a bug in seaborn - at least it could be better handled. 可能这是seaborn中的一个错误-至少可以更好地解决它。

You might have better success with this: 您可能会获得更好的成功:

import seaborn as sns
sns.distplot([1,2] * 10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM