Issue
I would like to change the color of the annotation text in a seaborn heatmap. By default the text in darker areas of the plot is white. However, I am trying to match the style of another plot so I would like the text to be black.
I have attached an example of my code below
ax = sns.heatmap(test, annot=True,
fmt='.2', cmap= custom_color_map)
ax.set_title('Seaborn Confusion Matrix with labels\n\n');
ax.set_xlabel('Predicted Values')
ax.set_ylabel('Actual Values ');
## Ticket labels - List must be in alphabetical order
ax.xaxis.set_ticklabels(['0','1', '2', '3, '4'])
ax.yaxis.set_ticklabels(['0','1', '2', '3, '4'])
As you can see the text on the diagonal is white because the cells are darker. I would like to change that to black.
Thank you for your assistance.
Solution
- You can define your proper style in the
annot_kws
argument onheatmap
function, and it's like in html.annot_kws
keyword arguments formatplotlib.axes.Axes.text()
Here's an example:
sns.heatmap(data.corr(), cmap='coolwarm', annot=True,
annot_kws={'fontsize': 12, 'fontstyle': 'italic', 'color':'b', 'alpha': 0.6,
'rotation': 'vertical', 'verticalalignment': 'center', 'backgroundcolor': 'w'})
You can find more info here in the vii. annot_kws part.
Answered By - Aladin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.