Networkx反转了一些边缘'在nx.Graph中订购

时间:2017-06-16 22:18:00

标签: python networkx

我对networkx有一个问题(Python 2.7):一些点坐标在图表中传递后会被反转。

以下是一个例子:

inputdata= [('766', '7628'),
 ('7233', '7369'),
 ('7233', '7575'),
 ('7233', '7576'),
 ('7233', '7577'),
 ('7235', '7236'),
 ('7369', '7575'),
 ('7369', '7576'),
 ('7369', '7577'),
 ('7370', '7377'),
 ('7575', '7576'),
 ('7575', '7577'),
 ('7576', '7577'),
 ('7578', '7579'),
 ('7580', '7587'),
 ('7607', '7608'),
 ('7673', '7674'),
 ('7676', '7627'),
 ('7677', '7678'),
 ('7623', '7624'),
 ('7628', '7629'),
 ('7637', '7633')]

Gr = nx.Graph()
Gr.add_edges_from(inputdata)

Gr.edges()
Out[108]: 
[('7370', '7377'),
 ('7580', '7587'),
 ('766', '7628'),
 ('7678', '7677'),
 ('7676', '7627'),
 ('7674', '7673'),
 ('7369', '7575'),
 ('7369', '7233'),
 ('7369', '7577'),
 ('7369', '7576'),
 ('7575', '7233'),
 ('7575', '7577'),
 ('7575', '7576'),
 ('7577', '7233'),
 ('7577', '7576'),
 ('7576', '7233'),
 ('7579', '7578'),
 ('7637', '7633'),
 ('7236', '7235'),
 ('7624', '7623'),
 ('7629', '7628'),
 ('7608', '7607')]

例如,在调用('7607', '7608')时,请参阅('7608', '7607')对{。}}。

我需要检索与输入数据相同的顺序。

1 个答案:

答案 0 :(得分:3)

如果订单很重要,您可能需要考虑使用有向图

Gr = nx.DiGraph()

否则,我不确定保持节点顺序的目的是什么。