下面的代码片段应该显示数据集的热图,如第一个图像:
colormap = plt.cm.RdBu
plt.figure(figsize=(18, 15))
plt.title('Pearson Correlation of Features', y=1.05, size=50)
sns.heatmap(df.corr(), linewidths=0.1, vmax=1.0, square=True, cmap=colormap, linecolor='white', annot=True)
plt.show()

但是,我的RdBu在PyCharm中高亮显示,警告消息说:
在“cm.py”中找不到引用“RdBu”
有几篇文章基本上表明语法是正确的,我没有遗漏任何包。我拿了这张空地图做错了什么?

发布于 2021-09-03 08:44:40
在图形代码之前,我遗漏了以下代码:
for c in df.columns:
if df[c].dtype == 'object':
lbl = LabelEncoder()
lbl.fit(list(df[c].values))
df[c] = lbl.transform(list(df[c].values))https://stackoverflow.com/questions/69040928
复制相似问题