使用底图在python中绘制地图上的点

问题描述 投票:0回答:1

所以我在试图获得一些点来绘制(或者更确切地说是在地图上)时遇到了一些问题。

这是代码:

#!/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

无论我尝试过什么,我都无法将积分显示在地图上。所以我非常感谢对此的一些帮助。先感谢您。

python python-3.6 matplotlib-basemap
1个回答
0
投票

我想通了,我的Lats and lons向后退了这条线:

x, y = m(lons, lats)

我应该把它当作:

x, y = m(lats, lons)
© www.soinside.com 2019 - 2024. All rights reserved.