Custom Annotation Seaborn Heatmap

前端 未结 3 986
醉梦人生
醉梦人生 2020-12-01 09:30

I\'m using Seaborn in Python to create a Heatmap. I\'m able to annotate the cells with the values passed in, but I\'d like to add annotations that signify what the cell mean

3条回答
  •  囚心锁ツ
    2020-12-01 10:16

    I don't believe this is possible in the current version. If you are up to a hack-y workaround, you could do the following ...

    # Create the 1st heatmap without labels 
    sns.heatmap(data=df1, annot=False,)
    
    # create the second heatmap, which contains the labels,
    # turn the annotation on,
    # and make it transparent
    sns.heatmap(data=df2, annot=True, alpha=0.0)
    

    Note that you may have a problem with the coloring of your text labels. Here, I created a custom cmap to have all labels uniformly black.

提交回复
热议问题