我想给出将由 plot_graph_routes 创建的每条路线以提供单独的颜色。我可以通过@gboing在这里解释两条路线。但是我有很多路线,所以我确实尝试循环解决它。
G = ox.graph_from_place('München, Oberbayern, Bayern, Deutschland', network_type='drive_service', simplify=True)
G_projected = ox.project_graph(G)
#%%
ox.config(log_console=True, use_cache=True)
colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w']
rc = []
nc = []
for r in range(len(routes)-1):
if r == 0:
rc.extend(colors[r] * (len(routes[r]) - 1))
else:
rc.extend(colors[r] * len(routes[r]))
nc.extend([colors[r], colors[r]])
fig, ax = ox.plot_graph_routes(G_projected, [routes], fig_height=40,route_color=rc, orig_dest_node_color=nc, node_size=0)
如果我这样做,我会收到以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-32-956a08875e0e> in <module>
9 rc.extend(colors[r] * len(routes[0][r]))
10 nc.extend([colors[r], colors[r]])
---> 11 fig, ax = ox.plot_graph_routes(G_projected, [routes[0]], fig_height=40,route_color=rc, orig_dest_node_color=nc, node_size=0)
12
13
~\Anaconda3\lib\site-packages\osmnx\plot.py in plot_graph_routes(G, routes, bbox, fig_height, fig_width, margin, bgcolor, axis_off, show, save, close, file_format, filename, dpi, annotate, node_color, node_size, node_alpha, node_edgecolor, node_zorder, edge_color, edge_linewidth, edge_alpha, use_geom, orig_dest_points, route_color, route_linewidth, route_alpha, orig_dest_node_alpha, orig_dest_node_size, orig_dest_node_color, orig_dest_point_color)
732 origin_node = route[0]
733 destination_node = route[-1]
--> 734 orig_dest_points_lats.append(G.nodes[origin_node]['y'])
735 orig_dest_points_lats.append(G.nodes[destination_node]['y'])
736 orig_dest_points_lons.append(G.nodes[origin_node]['x'])
~\Anaconda3\lib\site-packages\networkx\classes\reportviews.py in __getitem__(self, n)
176
177 def __getitem__(self, n):
--> 178 return self._nodes[n]
179
180 # Set methods
TypeError: unhashable type: 'list'
感谢您的任何建议。