matplotlib 底图绘制 lat/long 坐标不正确

matplotlib Basemap plotting lat/long coordinates incorrectly

我正在尝试学习 matplotlib 和映射函数 Basemap,并试图在地图上绘制一个简单的 lat/long 坐标列表。但是,将底图坐标转换为简单的 x/y 坐标会在地图上疯狂地绘制点,我无法弄清楚原因。我的代码如下:

locationData = parseFile(locationFile)

fig = plt.figure(figsize=(8,8))
m = Basemap(projection='merc', resolution='h',
            llcrnrlat=49, llcrnrlon=-13.5,
            urcrnrlat=59.5, urcrnrlon=4)
m.drawcoastlines()
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='green', lake_color='aqua')

index=0
for entry in locationData:
    lat = entry["latitudeE7"]/1E7
    long = entry["longitudeE7"]/1E7
    x,y = m(lat, long)
    print("Plotting {} {} to x{} y{}".format(lat,long,x,y))
    plt.plot(x,y, 'ok', markersize=20)
    # break at 30 points for testing
    if index>30: break
    index+=1
plt.show()

这是我从 print 语句得到的输出:

Plotting 52.------- 1.------- to x79364--.------- y-31476--.-------
Plotting 52.------- 1.------- to x79368--.------- y-31475--.-------
Plotting 52.------- 1.------- to x79362--.------- y-31471--.-------
Plotting 52.------- 1.------- to x79361--.------- y-31472--.-------
Plotting 52.------- 1.------- to x79360--.------- y-31475--.-------
Plotting 52.------- 1.------- to x79365--.------- y-31476--.-------
Plotting 52.------- 1.------- to x79361--.------- y-31476--.-------
...

出于显而易见的原因,我已经审查了确切的值,但您可以看到指向英国的 52°N 1°E 的预期值被严重偏离了英国的图表。将地图扩展到全球显示它正在绘制马达加斯加北海岸外的点。

我从 Google 位置历史下载中获取坐标,然后将其除以 10^7,因为它们存储为整数。打印语句显示这些正在被正确解析。

我是 matplotlib 和底图的新手,运行 Python 3.6 on Windows 10。有什么帮助吗?

编辑 - 发布我的旧代码我的错误

来自basemap documentation

Calling a Basemap class instance with the arguments lon, lat will convert lon/lat (in degrees) to x/y map projection coordinates (in meters). If optional keyword inverse is True (default is False), the inverse transformation from x/y to lon/lat is performed.

而不是 x,y = m(lat, long) 你因此需要

x,y = m(long, lat)