我正在尝试将热图中的一行更改为其他颜色
以下是数据集:
m = np.array([[ 0.7, 1.4, 0.2, 1.5, 1.7, 1.2, 1.5, 2.5],
[ 1.1, 2.5, 0.4, 1.7, 2. , 2.4, 2. , 3.2],
[ 0.9, 4.4, 0.7, 2.3, 1.6, 2.3, 2.6, 3.3],
[ 0.8, 2.1, 0.2, 1.8, 2.3, 1.9, 2. , 2.9],
[ 0.9, 1.3, 0.8, 2.2, 1.8, 2.2, 1.7, 2.8],
[ 0.7, 0.9, 0.4, 1.8, 1.4, 2.1, 1.7, 2.9],
[ 1.2, 0.9, 0.4, 2.1, 1.3, 1.2, 1.9, 2.4],
[ 6.3, 13.5, 3.1, 13.4, 12.1, 13.3, 13.4, 20. ]])
data = pd.DataFrame(data = m)
现在我正在使用seaborn热图,我只能创建如下内容:
cmap = sns.diverging_palette(240, 10, as_cmap = True)
sns.heatmap(data, annot = True, cmap = "Reds")
plt.show
我希望更改最后一行的配色方案,以下是我想要实现的目标(我在Excel中完成了此操作):
我可以用Python和seaborn heatmap实现这一点吗?谢谢大家!
可以一分为二,遮罩不需要的部分,然后分别打印:
输出:
NB。您需要根据实际的索引名调整
loc[…]
参数相关问题 更多 >
编程相关推荐