【问题标题】:GeoPandas and OSMnx- plotting on mapGeoPandas 和 OSMnx - 在地图上绘图
【发布时间】:2019-08-06 13:58:36
【问题描述】:


我想在地图上绘制我的 Geopandas df。作为背景,我想要该地区的(道路)地图。喜欢 OSMnx 包,我想弄清楚如何使用它的输出(shapefile?网络?)作为我的绘图背景

import osmnx as ox 
G= ox.core.graph_from_place('Chengdu City', network_type='all_private', 
                            simplify=True, retain_all=False, 
                            truncate_by_edge=False, name='unnamed', 
                            which_result=1, buffer_dist=None, timeout=180, 
                            memory=None, 
                            max_query_area_size=2500000000, 
                            clean_periphery=True, infrastructure='way["highway"]', custom_filter=None)

这是网络图,现在我想在上面绘制我的 geopandas 点(和线):

dict= {'take_lat_1k': [31.47, 31.51, 30.54, 30.54],'take_lng_1k': [104.75, 104.67, 103.97, 103.97], 
     'return_lat_1k': [31.48, 31.49, 30.54, 30.54],'return_lng_1k': [104.71, 104.69, 103.97, 103.97]}
df= pd.DataFrame(dict)
# creating Geopandas geometries 
geometry_t = [Point(xy) for xy in zip(df["take_lng_1k"],df["take_lat_1k"])]
geometry_r = [Point(xy) for xy in zip(df["return_lng_1k"],df["return_lat_1k"])]
lines = [LineString(ab) for ab in zip (geometry_t, geometry_t)]

# osmnx network as the fig,ax
fig, ax = ox.plot_graph(G)

# creating Geodf
geo_df_t = gpd.GeoDataFrame(df, geometry=geometry_t)
geo_df_t.plot(ax=ax, markersize = 20, color = "red" , alpha=1)
geo_df_line = gpd.GeoDataFrame(df, geometry=lines)
geo_df_line.plot(ax=ax,  color = "black"  , alpha=1  )
geo_df_r = gpd.GeoDataFrame(df, geometry=geometry_r)
geo_df_r.plot(ax=ax, markersize = 20, color = "green"  , alpha=1    )
plt.show()

我得到的是漂亮的 osmnx 网络图,但它们之间没有我的点和线。这也出现在图像的底部:图形大小为 432x288,带有 0 个轴
我这样做对吗..?

【问题讨论】:

    标签: python dictionary plot geopandas osmnx


    【解决方案1】:

    根据OSMnx documentation,使用show 和close 参数来防止在您添加所有内容之前显示和关闭绘图图。此外,为您的点和线提供更高的 zorder 以确保它们绘制在底图之上而不是底图之下:

    fig, ax = ox.plot_graph(G, show=False, close=False)
    geo_df_t.plot(ax=ax, markersize = 20, color="red" , alpha=1, zorder=7)
    geo_df_line.plot(ax=ax, color = "black", alpha=1, zorder=8)
    geo_df_r.plot(ax=ax, markersize = 20, color="green", alpha=1, zorder=9)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2019-09-05
      • 2020-03-05
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多