python - 在 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()
解决方案
推荐阅读
- php - PHP动态导航子菜单
- node.js - MongoNetworkError:连接 ECONNREFUSED 172.18.0.2:27017
- python - 如何在 VS Code 中更改 Python 版本
- angular - 反应式表单是围绕可观察的流构建的
- windows - 我们可以使用 NMAKE.EXE 作为 GNU Make 的替代品吗?
- c# - 使用 COM 互操作从 VSTO C# 列出现有 Access 实例的 MS Access 表
- android - 如何在 opentok Cordova 中的发布者视频顶部显示 HTML 按钮
- javascript - 如何使用复选框禁用使用 Javascript 的表单“月”输入?
- python - 轮询命令 discord.py
- javascript - 如何在单击时使用 Javascript 折叠部分?