我正在尝试绘制一个网络,其中边缘根据其 Opens 街道地图属性(“高速公路”)具有不同的颜色。如果我使用它,它会起作用ox.graph,但是,这会生成一个静态地图。如果我使用,ox.plot.plot_graph_folium()如果我将所有边缘设置为具有相同的颜色,我只会得到一个交互式地图。如果我为 edge_color 分配一个颜色列表,它就不起作用。
import osmnx as ox
address_name='19, Molstraat, Van Leeuwenhoekkwartier, Delft, South Holland, Netherlands, 2611EM, Netherlands'
graph=ox.graph_from_address(address_name, distance=300)
ec = ['skyblue' if data['highway']=='footway'
else 'paleturquoise' if data['highway']=='residential'
else 'orange' if data['highway']=='cycleway'
else 'sienna' if data['highway']=='service'
else 'lightgreen' if data['highway']=='living street'
else 'grey' if data['highway']=='secondary'
else 'lightskyblue' if data['highway']=='pedestrian'
else 'black' for u, v, key, data in graph.edges(keys=True, data=True)]
#this works, but is static
ox.plot_graph(graph,fig_height=8,fig_width=8,node_size=0, edge_color=ec)
#this does not work
import folium
ox.plot.plot_graph_folium(graph, popup_attribute='highway',edge_color=ec) …Run Code Online (Sandbox Code Playgroud)