matplotlib底图错误地绘制了纬度/经度坐标 [英] matplotlib Basemap plotting lat/long coordinates incorrectly
问题描述
我正在尝试学习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