木星Python海生热图没有显示所有的相关性

2024-09-25 10:23:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我对关联的热图有点麻烦。它没有显示我感兴趣的所有专栏。在

这是我的代码:

sns.set(style="white")
# Compute the correlation matrix
corr = data.corr()

# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

# Set up the matplotlib figure
f, ax = plt.subplots(figsize=(11, 9))

# Generate a custom diverging colormap
cmap = sns.diverging_palette(220, 10, as_cmap=True)

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, mask=mask, cmap=cmap, vmax=1, vmin=-1, center=0,
        square=True, linewidths=1, cbar_kws={"shrink": .5})

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

Part of the result

这里有一小段数据列丢失了

Snip of the columns missing

问题是,正如你所见,我错过了CIVIST,F,L 我想不出办法解决它。在

谨致问候 基督徒


Tags: ofthe代码truenpmaskgenerate感兴趣
2条回答

试着增加绘图的大小。 它对我有用

corr=df.corr()
plt.subplots(figsize=(20,15))
sns.heatmap(corr)

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

'CIVIST_D' in corr.index

相关问题 更多 >