Networkx OSMNX 和 Folium 绘制不同颜色的边缘

Networkx OSMNX and Folium plotting different coloured edges

我一直在尝试将不同的 osmnx 图叠加到 folium 上,但一直无法做到。我想用一个简单的 osmnx 图实现与下图所示相同的效果,但不是在 folium 上,红色边缘为红色,其他边缘为不同颜色。

fig, ax = ox.plot_graph_routes(G,max_response_edges, bgcolor='k', node_size=30, node_color='#999999', node_edgecolor='none', node_zorder=2,
                        edge_color='#555555', edge_linewidth=1.5, edge_alpha=1,figsize = (20,20))

我试过使用下面的代码:

H = G.copy()
H1 = G.copy()
H.remove_edges_from(G.edges - set(map(lambda x: tuple(x)+(0,),max_response_edges)))
m = ox.folium.plot_graph_folium(H,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'red',weight= 10)
H1.remove_edges_from(set(map(lambda x: tuple(x)+(0,),max_response_edges)))
n = ox.folium.plot_graph_folium(H1,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'blue',weight= 10)
n.add_to(m)
m

我尝试使用 m.add_child()m.add_to() 但 none 被证明是有用的。 发布了类似的堆栈溢出问题,但这没有用。可以做 folium overlay 吗?

通过以下代码搞定

H = G.copy()
H1 = G.copy()
H.remove_edges_from(G.edges - set(map(lambda x: tuple(x)+(0,),max_response_edges)))
m = ox.folium.plot_graph_folium(H,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'red',weight= 10)
H1.remove_edges_from(set(map(lambda x: tuple(x)+(0,),max_response_edges)))
m = ox.folium.plot_graph_folium(H1, graph_map = m,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'blue',weight= 10)
m

原来我遗漏了 graph_map=m 参数