If I already have a graph of a city in a figure, can I draw one or more routes on it afterwards? Until now I have created a graph within some bounding box which I then display with plt.show()
:
north, west = 47.45711622150064, 8.347885652066624
south, east = 47.31625428324118, 8.69120840316829
G = ox.graph.graph_from_bbox(north, south, east, west, network_type='drive', simplify=True, retain_all=False)
fig, ax = ox.plot.plot_graph(G)
plt.show()
So now you can see the graph in the matplot figure:
Then I want the user to enter start and destination coordinates and display the calculated shortest route on this figure. However, I have no idea how to plot the route on the figure after the figure is opened. This doesn't work:
G = ox.add_edge_speeds(G)
G = ox.add_edge_travel_times(G)
start_node = ox.distance.nearest_nodes(G, 8.435432953597548, 47.39719131318801)
end_node = ox.distance.nearest_nodes(G, 8.636963408494227, 47.3699935785241)
# Calculate the shortest path
route = nx.shortest_path(G, start_node, end_node, weight='travel_time')
# Plot the route and street networks
fig, ax = ox.plot_graph_route(G, route, route_linewidth=1, show=False, close=False)
plt.show()