使用底图在 python 地图上标绘点

plotting point on map in python using basemap

所以我在尝试在地图上绘制(或更确切地说显示)一些点时遇到了一些问题。

代码如下:

#!/usr/bin/python3

import matplotlib.pyplot as plt
import re

from mpl_toolkits.basemap import Basemap

m = Basemap(resolution='i', # c, l, i, h, f or None. crude, low, intermediate, high or full.
        projection='merc',
        lat_0=37.80, lon_0=-96.02,
        llcrnrlon=-125.22,
        llcrnrlat= 24.25,
        urcrnrlon=-66.83,
        urcrnrlat=49.26,
        area_thresh=10000)

m.drawcoastlines()
m.drawcountries()
m.drawstates()
m.drawmapboundary(fill_color='#46bcec')
m.fillcontinents(color='white',lake_color='#46bcec')


latlongs = []
lons = []
lats = []
with open('latlongsLocsNewBingAO.txt', 'r') as in_file:
    for line in in_file:
        line = line.replace('\n', '')
        latlongs.append(line)

for latlong in latlongs:
    if re.match(r'None ,*', latlong) is None:
        latlong = ",".join(latlong.split(",")[:2])
        latlong = latlong.replace('[', '')
        latlong = latlong.replace(']' ,'')
        ftuple = tuple(map(float, latlong.split(', ')))
        xT, yT = ftuple
        lons.append(xT)
        lats.append(yT)


x, y = m(lons, lats)
#print(x, y)
m.scatter (x, y, marker='o', color='r', zorder=5)

plt.show()

这里是我从该文件中提取的一些要点。

[40.9825820922852, -73.8059005737305] ,Scarsdale, New York 10583
[39.8815994262695, -83.0865631103516] ,Grove City, Ohio 43123
[35.4720306396484, -97.5210723876953] ,Oklahoma City, Oklahoma 73115
[29.7605800628662, -95.3696823120117] ,HOUSTON, TEXAS 1073
[32.8589515686035, -96.5462646484375] ,Garland, Texas 75043

无论我怎样尝试,我都无法在地图上显示这些点。因此,我将不胜感激对此的一些帮助。提前谢谢你。

我想出来了,我在这一行中把我的经纬度倒过来了:

x, y = m(lons, lats)

我应该把它当作:

x, y = m(lats, lons)