Python 为 seaborn 热图上的颜色条设置最大值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33779748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:58:52  来源:igfitidea点击:

Set Max value for color bar on seaborn heatmap

pythonmatplotlibheatmapseaborn

提问by Michael Berry

I need to set the max value on the seaborn heatmap cbarto 2. I've tried:

我需要将 seaborn 热图上的最大值设置cbar为 2。我试过:

cbar_kws = { 'ticks' : [0, 2] }
sns.heatmap(tiles, robust=True, fmt="f", cmap= 'RdBu_r', cbar_kws = cbar_kws)

But this doesn't work and the documentation isn't very clear. How would I do this properly?

但这不起作用,文档也不是很清楚。我将如何正确地做到这一点?

采纳答案by tmdavison

I think you want to use the vminand vmaxparameters for the heatmap, as described in the docs:

我认为您想对热图使用vminvmax参数,如文档中所述:

vmin, vmax: floats, optional

Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments.

vmin, vmax: 浮动,可选

锚定颜色图的值,否则它们是从数据和其他关键字参数推断出来的。

sns.heatmap(tiles, robust=True, fmt="f", cmap='RdBu_r', vmin=0, vmax=2)