所以我在试图获得一些积分来绘制(或者更确切地说是在地图上)时遇到了一些问题。
以下是代码:
#!/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
无论我尝试过什么,我都无法将积分显示在地图上。所以我非常感谢对此的一些帮助。提前谢谢。
答案 0 :(得分:0)
我明白了,我的Lats和Lons在这一行中倒退了:
x, y = m(lons, lats)
我应该把它当作:
x, y = m(lats, lons)