我正在尝试根据其 Opens 街道地图属性('highway')绘制一个边缘具有不同颜色的网络。如果我使用它,它会起作用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)
#this works, but is one color only
import folium
ox.plot.plot_graph_folium(graph,popup_attribute='highway',edge_color='blue')
这个类似的问题(stackoverflow)建议向每个边缘添加一个新列,然后修改plot_graph_folium
函数。此外,此修改不起作用。有人可以为我提供一个如何制作具有不同颜色边缘的交互式地图的示例吗?