【发布时间】:2021-11-05 12:19:19
【问题描述】:
如果我已经有一个城市的图表,我可以在上面画一条或多条路线吗?到目前为止,我已经在某个边界框内创建了一个图形,然后用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()
所以现在你可以在 matplot 图中看到图形了:
然后我希望用户输入起点和终点坐标,并在此图上显示计算出的最短路线。但是,我不知道打开图后如何在图上绘制路线。这不起作用:
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()
【问题讨论】:
-
我不确定是否可以在使用
plt.show时更改显示的数字。你可能想要讨论 here 或想要一个交互式 matplotlib 会话:matplotlib.org/stable/api/_as_gen/…
标签: matplotlib networkx osmnx