Seaborn lineplot,类型错误:输入类型不支持 ufunc 'isfinite'

Drz*_*rzw 8 python matplotlib seaborn

尝试使用 seaborn 绘制线图时出现以下错误。

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Run Code Online (Sandbox Code Playgroud)

重现错误的最小示例:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

dataset = {
    "x": [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],
    "y": [1.0, 2.3, 4.5, 1.2, 3.4, 5.3, 1.1, 2.4, 3.6, 1.1, 3.3, 5.3],
    "id": ["a", "a", "a", "b", "b", "b", "a", "a", "a", "b", "b", "b"],
    "seed": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
}

df = pd.DataFrame(data=dataset)
print(df.dtypes)

g = sns.lineplot(data=df, x="x", y="y", hue="id", errorbar="sd")
plt.show()
plt.close()
Run Code Online (Sandbox Code Playgroud)

我尝试检查所有输入和数据框列的数据类型,并将“id”更改为整数类型(即使这不是我的目标),并且错误仍然存​​在。

mwa*_*kom 9

Numpy 1.24.0有一个错误,会导致多个 seaborn 函数出现异常。该错误已得到修复,并且 numpy 已发布新版本来解决该问题。解决方案是按照安装 numpy 1.24.0 的方式安装 numpy 1.24.1。