Python NetworkX - Why are graphs always randomly rotated?

后端 未结 3 1963
旧巷少年郎
旧巷少年郎 2021-01-13 07:44

If I generate the same graph multiple times using NetworkX and Matplotlib it\'s rotated randomly on every generation:

Run 1:

Run 2:

Without changin

3条回答
  •  渐次进展
    2021-01-13 08:29

    I just found out that you can fix the initial state of the random generated graph: just seed the generator so it will always produce the same set of random positions.

    random_pos = nx.random_layout(graph, seed=42)
    pos = nx.spring_layout(graph, pos=random_pos)
    

提交回复
热议问题