0

I'm currently working on a heat map produced by the following data.

df = pd.DataFrame(
    data = {
                'Set_A' : [91, 91, 91, 90, 91, 91, 91],
                'Set_B' : [91, 92, 91, 89, 91, 91, 91],
                'Set_C' : [89, 90, 89, 88, 90, 89, 89],
                'model' : ['SVM', 'RF', 'LR', 'KNN', 'NB', 'MLP', 'LGB'],
                }
)
df = df.set_index('model')

sns.heatmap(df, cmap='Reds', annot=True, vmin=85, vmax=95, annot_kws={'color':'black'}, linewidths=.5);

Enter image description here

I have two questions.

  1. How can I change the color of the text in the heat map to white for 91 and above and black for 90 and below?

  2. Currently, the colorbar is 86 to 94. I would like to change this to show 85 to 95.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dai
  • 91
  • 8
  • It is 85 to 95, but those labels aren't displayed. – Trenton McKinney Jul 09 '22 at 15:29
  • Thank you. Is there any way to change the color of the numbers depending on the threshold value? – Dai Jul 09 '22 at 15:44
  • 1
    See updated [code and plot](https://i.stack.imgur.com/h4OhY.png) based on duplicate. As you can see, annotations are text, not numbers. – Trenton McKinney Jul 09 '22 at 16:27
  • If you don't set `annot_kws={'color':'black'}`, seaborn will automatically choose white text on dark squares and black text on light ones. To show color bar ticks from 85 till 95, you could add `cbar_kws={'ticks':range(85, 96)}`. Note that then there are 11 ticks, and matplotlib shows maximum 10 values by default. – JohanC Jul 09 '22 at 18:12

0 Answers0