【问题标题】:How to correct this code to place the points on the right part of the map?如何更正此代码以将点放置在地图的右侧?
【发布时间】:2019-08-22 17:52:37
【问题描述】:

我想在底图上绘制散点图,我的代码是这样的: %matplotlib 内联 从 mpl_toolkits.basemap 导入底图

创建图形和轴

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')


y,x = m(dfrt['lon'].values, dfrt['lat'].values)
m.scatter(x,y, marker="o", color='g', alpha=0.7, zorder=5)

plt.title("Localización de los Bikepoints")
plt.show()

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    BikePoints  003420  2019-08-22T11:14:02.787Z

但我得到的情节不正确,绿点应该在伦敦:

有什么想法吗?谢谢!!

【问题讨论】:

    标签: python scatter-plot matplotlib-basemap


    【解决方案1】:

    你有一个错字:

    y,x = m(dfrt['lon'].values, dfrt['lat'].values)
    

    应该是:

    x,y = m(dfrt['lon'].values, dfrt['lat'].values)
    

    根据 Matplotlib 文档: matplotlib basemap

    这是您期望的结果:

    【讨论】:

    • 谢谢@Artur,请多提一个问题,如何放大区域以更好地查看每个情节?
    【解决方案2】:

    看起来你的 x 和 y 颠倒了。尝试改变

    y,x = m(dfrt['lon'].values, dfrt['lat'].values)
    

    x,y = m(dfrt['lon'].values, dfrt['lat'].values)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-29
      • 2021-01-21
      • 2015-11-14
      • 2012-04-01
      • 2021-11-19
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      相关资源
      最近更新 更多