使用图案作为颜色 Osmnx 和 Python 绘制路线

Plot routes using pattern as a color Osmnx and Python

我想使用 osmnx 和 python 绘制在某些部分重叠的两条路线。我使用黄色作为路线 1 的颜色,蓝色作为路线 2 的颜色。使用图片阐明我的意思:

这只是路线1的地块:

这只是路线2的情节:

这是路线1和路线2合在一起的情节:

这是我的代码中的示例片段:

ox.plot_graph_routes(Graph, route1, route_color=['y']*len(route1))
ox.plot_graph_routes(Graph, route2, route_color=['b']*len(route2))
ox.plot_graph_routes(Graph, route1+route2, route_color=['y']*len(route1) + ['b']*len(route(2))

正如您在路线 1 和路线 2 的图中看到的那样,路线 1 和路线 2 重叠的部分有一个 blue/yellow 阴影图案或类似的东西会更方便。

有谁知道如何定义一种颜色,例如蓝色和黄色,以便我可以将它传递给 plot_graph_routes 函数中的 'route_color' 参数?

1) 我在没有使用路线的情况下绘制了图表:

ox.plot_graph(Graph)

2)我想要黄色和蓝色的部分是route1route2的交集:

yellow_and_blue = list(set(route1).intersection(route2))

我只想说黄色的部分是route1route2的区别:

yellow = list(set(route1).difference(route2))

2) 由于我的路由 route1route2 是 OSM ID 列表,因此 yellow_and_blueyellow 也是。我使用以下方法提取了它们的 x 和 y 坐标:

yellow_and_blue_x = []
yellow_and_blue_y = []
for node in yellow_and_blue:
    yellow_and_blue_x += [Graph.nodes[node]['x']]
    yellow_and_blue_y += [Graph.nodes[node]['y']]

同样适用于 yellow

3) 现在我们有了要绘制的路线的 x 和 y 坐标列表,我们可以使用

plt.plot(yellow_and_blue_x, yellow_and_blue_y, linestyle = (0,(5,5)), color = 'yellow')
plt.plot(yellow_and_blue_x, yellow_and_blue_y, linestyle = (5,(5,5)), color = 'blue')

plt.plot(yellow_x, yellow_y, color = 'yellow')

将路线绘制到我们之前生成的地块上。