如何解决如何使用pyVis按照坐标系纬度和经度放置图形的节点?
我正在使用 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 举报,一经查实,本站将立刻删除。