Plot a route 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/openstreetmap/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).
route = ox.distance.shortest_path(G, orig, dest)
# Plot a route along a graph.
ox.plot.plot_graph_route(
G,
route,
route_color='r',
route_linewidth=4,
route_alpha=0.5,
orig_dest_size=100,
ax=None)
(<Figure size 576x576 with 1 Axes>, <AxesSubplot:>)