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

Set Max value for color bar on seaborn heatmap

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

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

但这不起作用,文档也不是很清楚。我该如何正确执行此操作?

我想你想为热图使用 vminvmax 参数,如 docs:

中所述

vmin, vmax : floats, optional

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

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