如何在Seaborn热力图中标注仅大于x的值

4

我想在我的seaborn热力图上仅标识大于0.4的值。

这是我的代码:

sns.set(font_scale=0.6)

sns.set(font_scale=0.6)
ax= sns.heatmap(corr, mask=mask, cmap=cmap, vmin=-1, vmax=+1, center=0,
            square=True, linewidths=.1, cbar_kws={"shrink": .82},annot=True,
            fmt='.1',annot_kws={"size":7})

ax.set_xticklabels(ax.get_xticklabels(), rotation=60)

这是我得到的: 在此输入图像描述 谢谢。
2个回答

6
通过简单循环解决问题,循环遍历各象限并仅在值大于0.4时设置注释。
for t in ax.texts:
    if float(t.get_text())>=0.4:
        t.set_text(t.get_text()) #if the value is greater than 0.4 then I set the text 
    else:
        t.set_text("") # if not it sets an empty text

enter image description here


0

从版本0.7.1开始,seaborn添加了一个标签数组选项,该数组与数据具有相同的形状(这里是文档):

# Generate some array to plot
arr = np.arange(16).reshape(4, -1)

# Generate annotation labels array (of the same size as the heatmap data)- filling cells you don't want to annotate with an empty string ''
annot_labels = np.empty_like(arr, dtype=str)
annot_mask = arr > 8
annot_labels[annot_mask] = 'T'  

# Plot hearmap with the annotations
ax= sns.heatmap(arr, annot=annot_labels, fmt='')

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接