使用散点数据集的热图 python matplotlib
我正在编写一个脚本来制作二维散布数据的热图。以下是我正在尝试做的一个玩具示例:
import numpy as np
from matplotlib.pyplot import*
x = [1,2,3,4,5]
y = [1,2,3,4,5]
heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
imshow(heatmap, extent = extent)
我应该期望“最温暖”的区域沿着 y=x,但它们却沿着 y=-x+5 显示,即热图以相反的方式读取一个列表方向。我不知道为什么会发生这种情况。有什么建议吗?
谢谢
I am writing a script to make a heatmap for scatter data on two dimensionS. The following is a toy example of what I am trying to do:
import numpy as np
from matplotlib.pyplot import*
x = [1,2,3,4,5]
y = [1,2,3,4,5]
heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
imshow(heatmap, extent = extent)
I should expect a the 'warmest' areas to be along y=x but instead they show up along y=-x+5 i.e the heatmap reads one list in the reverse direction. I am not sure why this is happening. Any suggestions?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
imshow
参数origin=lower
。默认情况下,它将数组的 (0,0) 元素设置在左上角。例如:
生成:
Try the
imshow
parameterorigin=lower
. By default it sets the (0,0) element of the array in the upper left corner.For example:
Produces:
为了使热图的外观与您在散点图中看到的保持一致,实际上可以使用:
Too keep the look of the heatmap consistent with what you see in the scatter, actually use: