繁体   English   中英

镜像 Seaborn 热图的色标,包括 colors 和标签

[英]Mirror the color scale of a Seaborn heatmap, both colors and labels

我有一个使用 Seaborn 模块生成的热图,如下所示

由于表格中的值通常随着与 MSL 的距离而增加(表格中的值增加),我想镜像色阶,使深蓝色位于底部,对应的 label(12),和浅黄色在顶部,与 label (3)。

我只找到了一种反转 colors 的方法,但随后标签仍然存在。 如何镜像整个比例(colors 和标签)?

谢谢!

颜色条轴上的invert_yaxis()反转刻度标签和颜色条( invert_xaxis()对水平颜色条执行相同的操作)。

Seaborn 的热图不会直接返回生成的颜色条的句柄。 它可以通过绘图的ax获得: cbar = ax.collections[0].colorbar

这是一个例子:

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

x, y = np.meshgrid(np.arange(20), np.arange(20))
arr = (x * y) % 10
ax = sns.heatmap(arr, annot=True, cbar=True)
cbar = ax.collections[0].colorbar
cbar.ax.invert_yaxis()
plt.show()

结果图

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM