How to show cycles in networkx graph drawing

后端 未结 1 1097
暖寄归人
暖寄归人 2020-12-04 00:20

I have a simple graph constructed using NetworkX as follows:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.DiGraph()
G.add_edges_from([(0,1),         


        
相关标签:
1条回答
  • 2020-12-04 01:02

    Graphviz does a great job of drawing arrows and self loops. (Non-trivial to implement in Matplotlib). Here is an example:

    import networkx as nx
    import matplotlib.pyplot as plt
    
    G = nx.DiGraph()
    G.add_edges_from(\[(0,1), (0,2), (1,1), (1,2)\])
    nx.write_dot(G,'graph.dot')
    
    # then run dot -Tpng graph.dot > graph.png
    

    enter image description here

    0 讨论(0)
提交回复
热议问题