问题描述
我正在使用 python 库 pyVis 和 Networkx 来可视化图表,其中每个节点是世界上某个地方的一个端口,每个链接是端口之间的路由。情况如下:使用 pyVis 我可以告诉它节点(x 和 y)的位置,但是当我使用端口的经度和纬度时,它没有正确放置它们,我想这是因为我正在使用坐标在 HTML 页面中,无需任何处理。我的问题是:我可以使用一些 pyVis 方法来告诉它位置是坐标,从而更改 HTML 页面的参考系统还是我必须编写代码才能做到这一点?
谢谢,我留下代码以备不时之需。
def create_display_attributes(attr: dict,edge: bool = False) -> dict:
if not edge:
return {
'title': attr['country'],'group': attr['region'],'x': attr['pos'][0],#lon
'y': attr['pos'][1] #lat
}
else:
return {
'color': color_edges[attr['year']]
}
def create_display_network(graph: nx.MultiDiGraph) -> nx.MultiDiGraph:
nx_graph = nx.MultiDiGraph()
nx_graph.add_nodes_from(
[
(node,create_display_attributes(attr))
for node,attr in graph.nodes(data=True)
]
)
nx_graph.add_edges_from(
[
(source,target,create_display_attributes(attr,edge=True))
for source,attr in graph.edges(data=True)
if source != target
]
)
return nx_graph
def draw_graph(graph: nx.MultiDiGraph,title):
nt = Network(height="100%",width="100%",directed=True,heading=title)
nt.from_nx(create_display_network(graph))
nt.show('nx.html')
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)