gpt4 book ai didi

python - 如何创建具有多个颜色图的热图?

转载 作者:行者123 更新时间:2023-12-03 21:58:11 25 4
gpt4 key购买 nike

如下图所示,我正在寻找一种简单的方法将两个或多个热图组合成一个,即具有多个颜色图的热图。

这个想法是将每个单元格分成多个子单元格。我找不到任何已经实现了这种可视化功能的python库。有人知道(至少)接近于此的东西吗?

A hea-tmap with 2 colomaps

最佳答案

您可以重构数组以在实际数据之间包含空列,然后创建一个屏蔽数组以绘制具有透明度的热图。这是添加空列的一种方法(可能不是最好的):

arr1 = np.arange(20).reshape(4, 5)
arr2 = np.arange(20, 0, -1).reshape(4, 5)
filler = np.nan * np.zeros((4, 5))

c1 = np.vstack([arr1, filler]).T.reshape(10, 4).T
c2 = np.vstack([filler, arr2]).T.reshape(10, 4).T
c1 = np.ma.masked_array(c1, np.isnan(c1))
c2 = np.ma.masked_array(c2, np.isnan(c2))

plt.pcolormesh(c1, cmap='bone')
plt.pcolormesh(c2, cmap='jet')

您也可以使用 np.repeat并将所有其他列屏蔽为@JohanC 注释
c1 = np.ma.masked_array(np.repeat(arr1, 2, axis=1), np.tile([True, False], arr1.size))
c2 = np.ma.masked_array(np.repeat(arr2, 2, axis=1), np.tile([False, True], arr2.size))

enter image description here

关于python - 如何创建具有多个颜色图的热图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61036609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com