Matplotlib:如何绘制x值的一维数组,y轴对应于热图?

时间:2015-04-13 22:12:15

标签: python matplotlib heatmap

我想为热图制作一个子图,其中y轴与热图(特征)的热轴匹配,但x轴是热图中每个特征所代表的分箱值的平均值的一些变换。下面是一个示例图:

example figure -- I'm trying to make the subplot on the right

我可以使用imshow制作热图,并且每个特征都有一个转换方法数组,索引与热图数组匹配。如何在我的示例图右侧生成子图?

1 个答案:

答案 0 :(得分:2)

两个主要方面是设置轴以共享y度量(sharey=True)和(如您所示)设置转换后的数据以使用相同的索引:

import matplotlib.pyplot as plt
from numpy.random import random
from numpy import var

H = random(size=(120,80))
Hvar = var(H, axis=1)
fig, axs = plt.subplots(figsize=(3,3), ncols=2, sharey=True, sharex=False)
plt.sca(axs[0])
plt.imshow(H) #heatmap into current axis
axs[0].set_ylim(0,120)
axs[1].scatter(Hvar, range(len(Hvar)))
plt.show()

enter image description here