Matplotlib:如何用对应于热图的 y-axis 绘制 x 值的一维数组?
Matplotlib: How does one plot a 1D array of x values with y-axis corresponding to a heatmap?
我想为热图制作一个子图,其中 y-axis 与热图(特征)的子图相匹配,但 x 轴是为热图。下面是一个示例图:
我可以使用 imshow 制作热图,并且我为每个具有与热图数组匹配的索引的特征提供了一组转换均值。如何生成示例图右侧的子图?
主要的两件事是设置坐标轴以共享 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()
我想为热图制作一个子图,其中 y-axis 与热图(特征)的子图相匹配,但 x 轴是为热图。下面是一个示例图:
我可以使用 imshow 制作热图,并且我为每个具有与热图数组匹配的索引的特征提供了一组转换均值。如何生成示例图右侧的子图?
主要的两件事是设置坐标轴以共享 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()