Plot several routes along a graph.
# OSMnx: New Methods for Acquiring, Constructing, Analyzing, and Visualizing Complex Street Networks
import osmnx as ox
ox.config(use_cache=True, log_console=False)
ox.__version__
'1.1.2'
query = '회현동, 중구, 서울특별시, 대한민국'
network_type = 'drive' # "all_private", "all", "bike", "drive", "drive_service", "walk"
# Create graph from OSM within the boundaries of some geocodable place(s).
G = ox.graph_from_place(query, network_type=network_type)
# Set origin and destination node ID
orig = list(G)[0]
dest = list(G)[-1]
/Users/junhyun/.pyenv/versions/3.8.5/envs/gis/lib/python3.8/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
# Solve shortest path from origin node(s) to destination node(s).
path1 = ox.shortest_path(G, orig, dest, weight='length')
path2 = ox.shortest_path(G, orig, dest, weight='travel_time')
# routes as a list of lists of node IDs
route = [path1, path2]
# Plot several routes along a graph.
fig, ax = ox.plot_graph_routes(G, route, route_colors=['r', 'y'], route_linewidths=4)
# Solve k shortest paths from an origin node to a destination node.
paths = ox.k_shortest_paths(G, orig, dest, k=2, weight='length')
# routes as a list of lists of node IDs
route = list(paths)
# Plot several routes along a graph.
fig, ax = ox.plot_graph_routes(G, route, route_colors=['r', 'y'], route_linewidths=4)