Python:如何在Seaborn Heatmap的定义值上将颜色条居中? [英] Python: How to centre a colorbar at a defined value for Seaborn Heatmap?
本文介绍了Python:如何在Seaborn Heatmap的定义值上将颜色条居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用seaborn绘制热图.因此,我的取值范围是0到5,我需要设定一个蓝色到红色的色标,白色为1,蓝色(低于1),红色为1到5. 我该怎么办?
I am trying to plot a heatmap using seaborn. So, 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. How can I do that?
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
参数,
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()
这篇关于Python:如何在Seaborn Heatmap的定义值上将颜色条居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文