首页 > 解决方案 > 在 mplleaflet 图中可视化 Networkx 图

问题描述

我有一个当前使用 networkx 可视化的车辆路由 (VRP) 模型输出。此外,我想知道是否有一种方法可以使用 mplleaflet 之类的包在真实世界地图上进一步添加 networkx 图。

下面是代码和图表的网络部分。

def DrawNetwork():
    G = nx.DiGraph()
    locations = DataProblem()._locations
    # print(locations)
    x = 0
    for vehicle_id in vlist:
        n = 0
        e = []
        node = []
        cl=PickupColor(x)

        for i in vehicle_id:
            G.add_node(i, pos=(locations[i][0], locations[i][1]))
            if n > 0:
                u = (vehicle_id[n - 1], vehicle_id[n])
                e.append(u)
                node.append(i)
                G.add_edge(vehicle_id[n - 1], vehicle_id[n])
                nx.draw(G, nx.get_node_attributes(G, 'pos'), nodelist=node, edgelist=e, with_labels=True,
                        node_color=cl, width=2, edge_color=cl,
                        style='dashed', font_color='w', font_size=12, font_family='sans-serif')
            n += 1
        x += 1
    # let's color the node 0 in black
    nx.draw_networkx_nodes(G, locations, nodelist=[0], node_color='k')
    plt.axis('on')
    # plt.show()

在此处输入图像描述

标签: pythonnetworkx

解决方案


推荐阅读