使用 Seaborn 的相关热图
Correlation Heatmap using Seaborn
我正在使用 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)
尝试按照此处 (https://python-graph-gallery.com/92-control-color-in-seaborn-heatmaps/) 的概述为 sns.heatmap(...) 添加 vmin 和 vmax 参数。
由于您的值范围是 0.6 到 1.0,您可以尝试设置 vmin = 0.55 和 vmax = 1.0 以将颜色范围限制在这些值内。
我正在使用 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)
尝试按照此处 (https://python-graph-gallery.com/92-control-color-in-seaborn-heatmaps/) 的概述为 sns.heatmap(...) 添加 vmin 和 vmax 参数。
由于您的值范围是 0.6 到 1.0,您可以尝试设置 vmin = 0.55 和 vmax = 1.0 以将颜色范围限制在这些值内。