在图像上绘制散点图

2024-04-19 01:09:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我绘制了一些由特定坐标和值定义的数据

我已经用散点图绘制了它,现在我想在图像的顶部绘制它,以反映数据点的位置。 我尝试使用matplotlib.image和导入img来显示图像。不幸的是,我所在位置的图像与数据不完全匹配(我相信是由于拉伸)

当我编辑extent时,Python要么编辑掉一些图像,而不是移动数据。我希望能够移动图像/裁剪图像以适应数据,或者使用某种包加载到地图中(因为我有坐标)。这需要显示丹麦的本地流

xy是我们的坐标(lat,lon),而z是每个坐标的值

plt.figure(figsize=(20,10))
plt.scatter(x,y, cmap = 'gist_heat' ,s=100,c=z)
plt.colorbar()
plt.ylim(np.min(y),np.max(y))
plt.xlim(np.min(x),np.max(x))

img = plt.imread("grindsted4_sattelit.png")
ext = [np.min(x),np.max(x), np.min(y), np.max(y)]
plt.imshow(img, zorder=0, extent=ext)

aspect=img.shape[0]/float(img.shape[1])*((ext[1]-ext[0])/(ext[3]-ext[2]))
plt.gca().set_aspect(aspect)

plt.show()

The plot are the colored dots, and the black and white dots are my coordinates in Google Earth 绘图是彩色点,黑白点是我在Google Earth中的坐标。
谢谢大家!


Tags: 数据图像编辑img定义matplotlibnp绘制