Jupiter Python seaborn 热图未显示所有相关性

Chr*_*ich 6 python heatmap correlation seaborn

我的相关性热图遇到一些问题。它没有显示我感兴趣的所有列。

\n\n

这是我的代码:

\n\n
sns.set(style="white")\n# Compute the correlation matrix\ncorr = data.corr()\n\n# Generate a mask for the upper triangle\nmask = np.zeros_like(corr, dtype=np.bool)\nmask[np.triu_indices_from(mask)] = True\n\n# Set up the matplotlib figure\nf, ax = plt.subplots(figsize=(11, 9))\n\n# Generate a custom diverging colormap\ncmap = sns.diverging_palette(220, 10, as_cmap=True)\n\n# Draw the heatmap with the mask and correct aspect ratio\nsns.heatmap(corr, mask=mask, cmap=cmap, vmax=1, vmin=-1, center=0,\n        square=True, linewidths=1, cbar_kws={"shrink": .5})\n
Run Code Online (Sandbox Code Playgroud)\n\n

该代码基于: https: //seaborn.pydata.org/examples/many_pairwise_correlations.html

\n\n

部分结果

\n\n

这是丢失的数据列的片段

\n\n

缺少列的片段

\n\n

正如您所看到的,问题是我缺少 CIVIST_D、F、L,并且我无法解决该问题。

\n\n

亲切的问候\n基督徒

\n

小智 6

尝试增加绘图的大小。这对我有用

corr=df.corr()
plt.subplots(figsize=(20,15))
sns.heatmap(corr)
Run Code Online (Sandbox Code Playgroud)


Jan*_*n K 0

不确定这是否有帮助,但请确保确实为您所需的列计算了相关性。例如:

'CIVIST_D' in corr.index
Run Code Online (Sandbox Code Playgroud)