如何将颜色条居中于Seaborn热图的定义值的中心? [英] How to centre a colorbar at a defined value for seaborn heatmap?

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

问题描述

我正在尝试使用seaborn绘制热图.我的取值范围是0到5,我需要设定一个蓝色到红色的色阶,白色为1,蓝色-低于1,红色为1-5.

I am trying to plot a heatmap using seaborn. I have values from 0 to 5 and I need to make a blue-to-red color scale, with white being at 1, blue- below 1, and red - from 1 to 5.

我该怎么做?

import seaborn as sns; sns.set()
hm=sns.heatmap(proportion, vmin=0, vmax=5, cmap='RdBu')

这是我要尝试的操作,但这不是自定义的...比例"是我的变量.我有什么可以做的吗?

This is what I try to do, but it is not customized... 'proportion' is my variable. Is there anything I can do?

推荐答案

也许您的意思是使用 center 自变量,

Maybe you mean to use the center argument,

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

data = np.random.rand(10,10)*5

ax = sns.heatmap(data, vmin=0,vmax=5,center=1,cmap="RdBu_r")

plt.show()

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

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