Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn Heatmap Colorbar Label as Percentage

Given this heat map:

import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)

How would I go about making the color bar values display in percent format? Also, what if I just wanted to show the first and last values on the color bar?

Thanks in advance!

like image 928
Dance Party2 Avatar asked Jan 15 '16 21:01

Dance Party2


1 Answers

iterating on the solution of @mwaskom, without creating the colorbar yourself:

import numpy as np
import seaborn as sns
data = np.random.rand(8, 12)
ax = sns.heatmap(data, vmin=0, vmax=1)
cbar = ax.collections[0].colorbar
cbar.set_ticks([0, .2, .75, 1])
cbar.set_ticklabels(['low', '20%', '75%', '100%'])

custom seaborn heatmap color bar labels

like image 159
Stefaan Avatar answered Sep 21 '22 18:09

Stefaan