如何反转Seaborn热图颜色条的颜色 [英] How to invert color of seaborn heatmap colorbar

查看:363
本文介绍了如何反转Seaborn热图颜色条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用热图可视化混乱矩阵。我喜欢标准颜色,但我想在浅橙色中设置0,在深紫色中设置最大值。

I use an heatmap to visualize a confusion matrix. I like the standard colors, but I would like to have 0s in light orange and highest values in dark purple.

我设法只使用另一组颜色(浅到深紫色),设置:

I managed to do so only with another set of colors (light to dark violet), setting:

colormap = sns.cubehelix_palette(as_cmap=True)
ax = sns.heatmap(cm_prob, annot=False, fmt=".3f", xticklabels=print_categories, yticklabels=print_categories, vmin=-0.05, cmap=colormap)

但是我想保留这些标准的。这是我的代码和得到的图像。

But I want to keep these standard ones. This is my code and the image I get.

ax = sns.heatmap(cm_prob, annot=False, fmt=".3f", xticklabels=print_categories, yticklabels=print_categories, vmin=-0.05)

推荐答案

默认cmap是 sns.cm.rocket 。要反转它,请将cmap设置为 sns.cm.rocket_r

The default cmap is sns.cm.rocket. To reverse it set cmap to sns.cm.rocket_r

使用您的代码:

cmap = sns.cm.rocket_r

ax = sns.heatmap(cm_prob,
                 annot=False,
                 fmt=".3f",
                 xticklabels=print_categories,
                 yticklabels=print_categories,
                 vmin=-0.05,
                 cmap = cmap)

这篇关于如何反转Seaborn热图颜色条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆