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”更改为整数类型(即使这不是我的目标),并且错误仍然存在。