有没有办法拉伸png图片以适合散点图?

时间:2019-09-29 23:41:03

标签: python pandas matplotlib openstreetmap

我需要了解一种使地图适合散点图点的方法

我一直在寻找解决方案,发现matplotlib and apect ratio of geographical-data plots有所帮助,但是我仍然不了解经度和纬度以及如何在matplotlib中使用它们。我尝试将方面更改为“相等”,但这只在要点上有很小的不同。目前,我的理论是我需要弄清楚如何通过做一些数学运算来找到正确的宽高比,以使图像适合这些点,但是我不确定要计算什么。

enter image description here

是当前的样子,从东部可以看到美国的总体形状。我将如何处理这个问题?我可以了解更多有关此内容的任何参考文献或资源都会很棒。

coordinatelist = [list of longitude and latitude coordinates]
#order of coordinates => [longitude min, longitude max, latitude min, latitude max]
coords = [-160.2, -65.5, 14.5, 65.7]
img= plt.imread(path)

width = 636 #width of image in pixels
height = 485 #height of image in pixels 

fig, axes = plt.subplots(figsize = (10,9))
axes.scatter(coordinatelist.longitude, coordinatelist.latitude, zorder=1, alpha= 0.4, c='r', s=8)
axes.set_xlim(coords[0],coords[1])
axes.set_ylim(coords[2],coords[3])
axes.imshow(img, zorder=0, extent = coords, aspect = 'auto')

plt.show()

我希望这些点与背景图像匹配,并在可能的情况下解释如何重现结果,以便使我获得更深刻的理解。谢谢!

1 个答案:

答案 0 :(得分:0)

已解决:

手动更改地图的范围是不必要且不一致的解决方案。 Openstreemap导出了我当时不知道的错误尺寸。我发现,仅在OSM上创建坐标框并不会实际导出指定的内容,除非您还设置了自定义尺寸。

在密切注意细节之后,导出了正确的尺寸图,并且该图适合了散点图。