Search code examples
pythonseabornheatmapplot-annotations

How to make one column of bold annotations on a heatmap


How to format (make bold) the annotations in one particular column in a Python Seaborn heatmap? (https://seaborn.pydata.org/generated/seaborn.heatmap.html)


Solution

  • Using Axes.texts and Text.set_fontweight:

    import numpy as np
    import seaborn as sns
    
    glue = sns.load_dataset("glue").pivot(columns="Model", index="Task", values="Score")
    ax = sns.heatmap(glue, annot=True)
    
    col = 0
    for idx in np.arange(glue.size).reshape(glue.shape)[:, col]:
        ax.texts[idx].set_fontweight('bold')
    

    Output:

    enter image description here