Reputation: 13
I need to plot edges conditional on the speed_kph
values such that edges with speed_kph
> A are color X and edges with speed_kph
< A are color Y. Is this possible in OSMnx?
From:
map = ox.graph_from_place('Paradise, California', network_type='drive')
I can plot: ox.plot_graph(map,bgcolor='#FFFFFF',edge_color='#000000',node_color='#000000');
Impute speed and travel time as described in other docs: map_cons_speed = ox.add_edge_speeds(map) map_cons_speed = ox.add_edge_travel_times(map_cons_speed)
Then extract edges: gdf_nodes, gdf_edges = ox.graph_to_gdfs(map_cons_speed)
But I can not figure out how the plot edges conditional on their speed limit.
Does anyone have any ideas? Thank you in advance for your time!
Upvotes: 0
Views: 870
Reputation: 6442
Create a list of edge colors based on that attribute:
import osmnx as ox
G = ox.graph_from_place('Paradise, California', network_type='drive')
G = ox.add_edge_speeds(G)
ec = ['y' if d < 50 else 'r' for u, v, d in G.edges(data='speed_kph')]
fig, ax = ox.plot_graph(G, node_alpha=0.1, edge_color=ec)
Or use the plot.get_edge_colors_by_attr
function to assign colors from a color map based on attribute values:
import osmnx as ox
G = ox.graph_from_place('Paradise, California', network_type='drive')
G = ox.add_edge_speeds(G)
ec = ox.plot.get_edge_colors_by_attr(G, 'speed_kph', cmap='plasma')
fig, ax = ox.plot_graph(G, node_alpha=0.1, edge_color=ec)
Upvotes: 1