Seaborn热图Colorbar标签作为百分比 [英] Seaborn Heatmap Colorbar Label as Percentage
本文介绍了Seaborn热图Colorbar标签作为百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出此热图:
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?
提前谢谢!
推荐答案
重复@mwaskom的解决方案,而无需自己创建颜色条:
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%'])
这篇关于Seaborn热图Colorbar标签作为百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文