如果我在不同的地图上绘制每条路线,结果是完美的。但是,我想要的是在单个地图上绘制多条路线。
我的代码是:
import osmnx as ox, networkx as nx, matplotlib.pyplot as plt, math as m
from haversine import haversine
org = (27.5075, 77.6779)
dst = (27.5067, 77.6694)
dist_fl = (int(haversine(org, dst)*1000))*2
G = ox.graph_from_point(org, simplify=False, distance=dist_fl)
orig_node = ox.get_nearest_node(G, org, method='euclidean')
target_node = ox.get_nearest_node(G, dst, method='euclidean')
nodes, edges = ox.graph_to_gdfs(G)
streets_per_node = ox.count_streets_per_node(G)
route = nx.shortest_path(G, source=orig_node, target=target_node,
weight='length', method='dijkstra')
node_route = nodes.loc[route]
route_list = [[1352186296, 1352186345], [1352186345, 1352186150, 1350260490,
1352186112, 1352186349, 1350260516, 4753659536L, 4753498382L], [4753498382,
4753498383L, 4753498390L], [4753498390, 4753498391L, 4753498392L,
4753498393L, 4753498394L], [4753498394, 4753498395L, 4753498396L,
4753498397L, 4753498398L], [4753498398, 4753478108L], [4753478108,
4753498399L, 4753498400L, 4753498401L], [4753498401, 4753498402L,
4753498403L], [4753498403, 4753498404L, 4753498405L, 4753657826L,
4753498406L, 4753498407L, 4753498408L, 4753498409L], [4753498409, 4753498410L, 4753498411L, 4753498412L], [4753498412, 3803339674L], [3803339674, 1352186110, 1352186253, 2265692728L], [2265692728, 1352186308, 1352186133, 1352186328, 1352186316, 1352186071, 1352186187, 1352186095], [1352186095, 1352186361, 1352186263]]
coord_list =[(77.6776527, 27.5069438), (77.6775911, 27.5061476), (77.6747421, 27.5061048), (77.6747447, 27.5065153), (77.6742216, 27.5065135), (77.6741438, 27.507339), (77.6740672, 27.5073159), (77.6738192, 27.5079793), (77.6736687, 27.5079667), (77.6726402, 27.5084229), (77.6720677, 27.5081814), (77.6717673, 27.5093129), (77.6704672, 27.5094812), (77.6690214, 27.507629)]
color_list = ['green', 'green', 'green', 'green', 'red', 'green', 'green', 'green', 'green', 'green', 'green', 'green', 'red', 'red']
fig, ax = ox.plot_graph_routes(G, route_list, fig_height=10, fig_width=10, save=True, filename='outfile_data', show=False, close=False, axis_off=False, edge_linewidth=1, node_size=10, route_color = color_list)
plt.show()