matplotlib底图错误地绘制了纬度/经度坐标 [英] matplotlib Basemap plotting lat/long coordinates incorrectly

查看:132
本文介绍了matplotlib底图错误地绘制了纬度/经度坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习matplotlib和映射功能Basemap,并试图在地图上绘制一个简单的经/纬度坐标列表.但是,将底图坐标转换为简单的x/y坐标会在地图上疯狂地绘制点,我不知道为什么.我的代码如下:

I am trying to learn matplotlib and the mapping function Basemap, and am trying to plot a simple list of lat/long coordinates on a map. However, the Basemap coordinate conversion to simple x/y coordinates are plotting points wildly off the map, and I can't work out why. My code is below:

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()

这是我从打印语句获得的输出:

And here is the output I get from the print statement:

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的预期值正在偏离英国的图表.将该地图扩展到整个地球,可以发现它正在绘制马达加斯加北海岸附近的点.

I've censored the exact values for obvious reasons, but you can see that the intended values of 52°N 1°E which points to the UK are being placed wildly off chart, which is of the UK. Expanding the map to the whole globe reveals that it is plotting the points off the north coast of Madagascar.

我正在从Google定位记录下载中获取坐标,然后将它们除以10 ^ 7,因为它们存储为整数.打印语句显示这些已正确解析.

I am taking the coordinates from a Google Location History download, then dividing it by 10^7 as they are stored as integers. The print statement shows that these are being parsed correctly.

我是matplotlib和basemap的新手,并且在Windows 10上运行Python 3.6.有帮助吗?

I am new to matplotlib and basemap, and am running Python 3.6 on Windows 10. Any help?

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

edit - posted my old code my mistake

推荐答案

来自

使用参数lon调用Basemap类实例,lat会将lon/lat(以度为单位)转换为x/y地图投影坐标(以米为单位).如果可选关键字inverse为True(默认为False),则执行从x/y到lon/lat的逆向转换.

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)

这篇关于matplotlib底图错误地绘制了纬度/经度坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆