如何使用 python 在伦敦地图上添加散点图
How to add a scatter plot over a map of London using python
我试图在伦敦地图上绘制此散点图,但它不正确,这是我的代码,地图有不同的大小,我想要一张地图,但我得到了 2 张。
这是我的数据框 (dfrt) 来获得散点图:
commonName id lat lon placeType url additionalProperties2 category key sourceSystemKey value modified
0 River Street , Clerkenwell BikePoints_1 51.529163 -0.109970 BikePoint /Place/BikePoints_1 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001023 2019-08-22T11:17:04.327Z
1 Phillimore Gardens, Kensington BikePoints_2 51.499606 -0.197574 BikePoint /Place/BikePoints_2 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001018 2019-08-22T11:10:02.34Z
2 Christopher Street, Liverpool Street BikePoints_3 51.521283 -0.084605 BikePoint /Place/BikePoints_3 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001012 2019-08-22T11:12:02.7Z
3 St. Chad's Street, King's Cross BikePoints_4 51.530059 -0.120973 BikePoint /Place/BikePoints_4 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001013 2019-08-22T11:08:02.047Z
4 Sedding Street, Sloane Square BikePoints_5 51.493130 -0.156876 BikePoint /Place/BikePoints_5 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName
这就是我试图得到的情节:
fig = plt.figure(figsize=(20, 10))
m = Basemap(projection='lcc', resolution='h',
lat_0=51.53, lon_0=0.08,
width=1E6, height=1.2E6)
m.shadedrelief()
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
a4_dims = (20, 10)
fig, ax = plt.subplots(figsize = a4_dims)
ax.scatter(dfrt['lat'], dfrt['lon'])
ax.set_title('Latitud y Longitud de la ubicación de BikePoints')
ax.set_xlabel('Latitud')
ax.set_ylabel('Longitud')
你能帮帮我吗?
您创建了 figure/axes 两次并最终绘制了 2 个图形。这是基于您的相关代码:
# create figure and axes
fig = plt.figure(figsize=(20, 10))
ax1 = plt.gca()
m = Basemap(projection='lcc', resolution='h', \
lat_0=51.53, lon_0=0.08,
width=1E6, height=1.2E6, ax=ax1)
m.shadedrelief()
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
# a4_dims = (20, 10)
# fig, ax = plt.subplots(figsize = a4_dims)
# uncomment to do scatter plot
#ax1.scatter(dfrt['lat'], dfrt['lon'])
ax1.set_title('Latitud y Longitud de la ubicación de BikePoints')
ax1.set_xlabel('Latitud')
ax1.set_ylabel('Longitud')
plt.show()
和(未完成的)情节:
编辑 1
地图上的数据绘制,这里是使用简单数据绘制的代码:
# sample data
lons = np.array([-5.371475, -1.569707, -0.892185])
lats = np.array([51.211262, 52.819886, 55.122479])
x,y = m(lons, lats)
# any of these code will plot dots on the map
#ax1.plot(*m(lons, lats), 'ro') # OK
#ax1.plot(x, y, 'ro') # OK
ax1.scatter(x, y, 25) # OK
对于来自 pandas' dataframe 的数据,尝试获取 lons
和 lats
如下:
lons = list(dfrt['lon'])
lats = list(dfrt['lat'])
然后按照上面的方法做。
我试图在伦敦地图上绘制此散点图,但它不正确,这是我的代码,地图有不同的大小,我想要一张地图,但我得到了 2 张。 这是我的数据框 (dfrt) 来获得散点图:
commonName id lat lon placeType url additionalProperties2 category key sourceSystemKey value modified
0 River Street , Clerkenwell BikePoints_1 51.529163 -0.109970 BikePoint /Place/BikePoints_1 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001023 2019-08-22T11:17:04.327Z
1 Phillimore Gardens, Kensington BikePoints_2 51.499606 -0.197574 BikePoint /Place/BikePoints_2 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001018 2019-08-22T11:10:02.34Z
2 Christopher Street, Liverpool Street BikePoints_3 51.521283 -0.084605 BikePoint /Place/BikePoints_3 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001012 2019-08-22T11:12:02.7Z
3 St. Chad's Street, King's Cross BikePoints_4 51.530059 -0.120973 BikePoint /Place/BikePoints_4 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName BikePoints 001013 2019-08-22T11:08:02.047Z
4 Sedding Street, Sloane Square BikePoints_5 51.493130 -0.156876 BikePoint /Place/BikePoints_5 {'$type': 'Tfl.Api.Presentation.Entities.Addit... Description TerminalName
这就是我试图得到的情节:
fig = plt.figure(figsize=(20, 10))
m = Basemap(projection='lcc', resolution='h',
lat_0=51.53, lon_0=0.08,
width=1E6, height=1.2E6)
m.shadedrelief()
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
a4_dims = (20, 10)
fig, ax = plt.subplots(figsize = a4_dims)
ax.scatter(dfrt['lat'], dfrt['lon'])
ax.set_title('Latitud y Longitud de la ubicación de BikePoints')
ax.set_xlabel('Latitud')
ax.set_ylabel('Longitud')
你能帮帮我吗?
您创建了 figure/axes 两次并最终绘制了 2 个图形。这是基于您的相关代码:
# create figure and axes
fig = plt.figure(figsize=(20, 10))
ax1 = plt.gca()
m = Basemap(projection='lcc', resolution='h', \
lat_0=51.53, lon_0=0.08,
width=1E6, height=1.2E6, ax=ax1)
m.shadedrelief()
m.drawcoastlines(color='gray')
m.drawcountries(color='gray')
# a4_dims = (20, 10)
# fig, ax = plt.subplots(figsize = a4_dims)
# uncomment to do scatter plot
#ax1.scatter(dfrt['lat'], dfrt['lon'])
ax1.set_title('Latitud y Longitud de la ubicación de BikePoints')
ax1.set_xlabel('Latitud')
ax1.set_ylabel('Longitud')
plt.show()
和(未完成的)情节:
编辑 1
地图上的数据绘制,这里是使用简单数据绘制的代码:
# sample data
lons = np.array([-5.371475, -1.569707, -0.892185])
lats = np.array([51.211262, 52.819886, 55.122479])
x,y = m(lons, lats)
# any of these code will plot dots on the map
#ax1.plot(*m(lons, lats), 'ro') # OK
#ax1.plot(x, y, 'ro') # OK
ax1.scatter(x, y, 25) # OK
对于来自 pandas' dataframe 的数据,尝试获取 lons
和 lats
如下:
lons = list(dfrt['lon'])
lats = list(dfrt['lat'])
然后按照上面的方法做。