I'm trying to plot a network where edges have different colors according to their Opens street map attribute ('highway'). It works if I use ox.graph
, however, this generates a static map. If I use ox.plot.plot_graph_folium()
I only get an interactive map if I set all edges to have the same color. If I assign to edge_color a list of colors it doesn't work.
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')
This similar question (stackoverflow) suggests adding a new column to each edge and then modify the plot_graph_folium
function. Also, this modification is not working. Could someone provide me with an example of how to make an interactive map with edges of different colors?