简体   繁体   English

如何影响图形节点的位置以进行可视化?

[英]How to affect positions to the graph nodes for visualization?

I have a graph that I read with Networkx from a Dotfile , and to visualize it I need to affect position (x,y) to each node.我有一个图表,我用NetworkxDotfile读取,为了将其可视化,我需要影响每个节点的位置 (x,y)。 How can I do that ?我怎样才能做到这一点 ?

For visualization, I use Plotly offline mode on python3.6 , and for that I will need the positions for the edge and nodes.对于可视化,我在 python3.6 上使用Plotly离线模式,为此我需要边缘和节点的位置。 For now , I try giving random values and that seems to not being working at all现在,我尝试给出随机值,但这似乎根本不起作用

Basically, the code i use for plotting is this one : https://plot.ly/python/network-graphs/ the algorithm uses 'pos' from the random created Graph , but for me , I don't have thoses coordonates and I don't have any idea how to generate them.基本上,我用于绘图的代码是这样的: https ://plot.ly/python/network-graphs/ 算法使用随机创建的 Graph 中的“pos”,但对我来说,我没有那些坐标和我不知道如何生成它们。

The problem you are trying to solve is known as graph layouts .您尝试解决的问题称为图形布局 There are some graph layout algorithms in networkx: networkx.drawing.layout . networkx 中有一些图形布局算法: networkx.drawing.layout Here is the example:这是示例:

import networkx as nx

G = nx.Graph()
G.add_nodes_from([1,2,3,4,5])
G.add_edges_from([(1,2),(2,3),(2,4),(4,5)])
nx.spring_layout(G)

Returns coordinates of all nodes:返回所有节点的坐标:

{1: array([-0.73835686,  0.38769421]),
 2: array([-0.11386106,  0.22912486]),
 3: array([0.14264776, 0.81717097]),
 4: array([ 0.21475452, -0.43399004]),
 5: array([ 0.49481564, -1.        ])}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM