change certain squares in a seaborn heatmap

前端 未结 2 611
南旧
南旧 2020-12-13 16:37

Say I have a heatmap that looks like this (axes are trimmed off):

I want to be able to alter certain squares to denote statistical significance. I know that I could

2条回答
  •  独厮守ぢ
    2020-12-13 16:54

    You could plot twice, applying a mask to the cells you do not want to emphasize the second time:

    import numpy as np
    import seaborn as sns
    x = np.random.randn(10, 10)
    sns.heatmap(x, annot=True)
    sns.heatmap(x, mask=x < 1, cbar=False,
                annot=True, annot_kws={"weight": "bold"})
    

提交回复
热议问题