我正在用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)
尝试为sns.heatmap(…)添加vmin和vmax参数,如下所述(https://python-graph-gallery.com/92-control-color-in-seaborn-heatmaps/)
由于值的范围为0.6到1.0,因此可以尝试设置vmin=0.55和vmax=1.0以将颜色范围限制为这些值
相关问题 更多 >
编程相关推荐