【发布时间】:2018-01-23 16:19:00
【问题描述】:
我尝试制作一个程序,用于根据参与者的点击绘制热图。有增加和减少情绪的两个身体。
我想用蓝色(更强烈的蓝色 = 更多的点击次数)和红色的右体显示点击强度。
问题是我需要将它显示在一个主体中,并且还需要与我看到热图的背景图像一起显示。
x=blue[:,1]
y=blue[:,2]
ax = plt.gca()
heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.imshow(heatmap.T, extent=extent, origin='lower')
ax = plt.gca()
ax.invert_yaxis()
plt.show()
x1=red[:,1]
y1=red[:,2]
ax = plt.gca()
heatmap, xedges, yedges = np.histogram2d(x1, y1, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.clf()
plt.imshow(heatmap.T, extent=extent, origin='lower')
ax = plt.gca()
ax.invert_yaxis()
plt.show()
plt.imshow(image)
imageFile = cbook.get_sample_data('C:\\Users\\Admin\\Desktop\\pythonpca\\result.png')
image = plt.imread(imageFile)
plt.plot(all_samples[0:240,0],all_samples[0:240,1], 'o', markersize=3, color='blue', alpha=0.5, label='increase')
plt.imshow(image)
通过这个,我得到了左侧身体点击的热图、右侧身体点击的热图以及左右身体的图片。我希望它们都在同一张图片中,带有蓝色和红色的热点。我正在附上我得到的图片。
2张尸体图片(我在上面画了蓝点,但我不需要这些点):
左右身体的热图:
如果我应该添加更多信息,请告诉我。
【问题讨论】:
-
也许你应该看看
seaborn它是一个很好的matplotlib 包装器,还有一些不错的热图 -
如果你可以通过 e.g. 来表达前后正数和负数,您可以使用发散的颜色图 matplotlib.org/users/plotting/colormaps/lightness_03.png matplotlib.org/users/colormaps.html#diverging 我想到目前为止您的方法还不错,您只需将右侧绘图的坐标转换为左侧坐标,例如通过从 x 值中减去偏移量。
标签: python matplotlib heatmap