使用Seaborn的相关热图

2024-09-25 10:20:09 发布

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

我正在用Seaborn绘制相关热图。相关性范围为0.6-1。我正在使用以下代码。我的问题是所有的细胞颜色都一样。我如何在颜色上加强更多的差异

mask = np.triu(np.ones_like(corr, dtype=bool))

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

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

# Draw the heatmap with the mask and correct aspect ratio
sns.heatmap(corr, 
            mask=mask, 
            cmap=cmap, 
            vmax=.3, 
            center=0,
            square=True, 
            linewidths=.5,
            annot = True,
            fmt='.2f', 
            annot_kws={'size': 10},
            cbar_kws={"shrink": .75})

plt.title('Asset Correlation Matrix')
plt.tight_layout()
ax.tick_params(axis = 'x', labelsize = 8)
ax.set_ylim(len(corr)+1, -1)

Correlation


Tags: thetrue颜色nppltmaskseabornax