GeoPandas和OSMnx-在地图上绘制 [英] GeoPandas and OSMnx- plotting on map

查看:132
本文介绍了GeoPandas和OSMnx-在地图上绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想在地图上绘制我的Geopandas df.作为背景,我想要该区域的(道路)地图.热爱OSMnx软件包,我试图弄清楚如何将其输出(shapefile?网络?)用作绘图背景


I want to plot my Geopandas df on a map. as a background i want a (road) map of the area. loving the OSMnx package, i'm trying to figure out how to use it's output (shapefile? network?) as my plot background

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)

这是网络图,现在我想在其上绘制我的地理熊猫点(和线):

this is the network graph, now i want to plot my geopandas points (and lines) on it:

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 netwrok图,但是它们之间没有点和线.也会出现在图像底部:图形尺寸432x288(带有0个轴)
我这样做对吗?

and what i'm getting is the pretty osmnx netwrok graph, but without my points and lines between them. also this appears at the bottom of the image: Figure size 432x288 with 0 Axes
am I doing this right..?

推荐答案

每个

Per the OSMnx documentation use the show and close arguments to prevent showing and closing the plotting figure before you've added everything to it. Also, give your points and lines a higher zorder to ensure they're plotted on top of the basemap rather than under it:

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

这篇关于GeoPandas和OSMnx-在地图上绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆