How to stop Networkx from changing the order of edges when adding them from a list?

前端 未结 2 958
攒了一身酷
攒了一身酷 2021-01-21 08:23

Adding edges from a list to a graph in NetworkX (python) changes the order of the edges, which causes problems for me when drawing the Graph. As example:

import          


        
2条回答
  •  无人共我
    2021-01-21 09:06

    If you use a traversal algorithm you can get the edges in the order they were visited in the path

    ```

    paths = nx.all_simple_paths(G, source=0, target=3) for path in map(nx.utils.pairwise, paths): ... print(list(path)) [(0, 1), (1, 2), (2, 3)] [(0, 1), (1, 3)] [(0, 2), (2, 1), (1, 3)] [(0, 2), (2, 3)] [(0, 3)] ```

提交回复
热议问题