如何在 Seaborn 热图上仅注释大于 x 的值

mic*_*ekh 5 python annotations heatmap seaborn pearson-correlation

我不仅想在我的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)
Run Code Online (Sandbox Code Playgroud)

这就是我得到的: 在此处输入图像描述

谢谢

mic*_*ekh 7

通过一个简单的循环解决了问题,该循环迭代象限并仅在值大于 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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述