Networkx: Overlapping edges when visualizing MultiGraph

前端 未结 4 1928
迷失自我
迷失自我 2020-11-29 09:52

The following multigraph plots correctly (i.e. parallel edges do not overlap) using graphviz neato to generate a png (as shown in this answer)

import network         


        
4条回答
  •  遥遥无期
    2020-11-29 10:15

    An improvement to the answer above is adding the connectionstyle argument to nx.draw:

    import networkx as nx
    G = nx.DiGraph()
    G.add_nodes_from([0,1])
    pos = nx.circular_layout(G)
    nx.draw_networkx_nodes(G, pos, connectionstyle='arc3, rad = 0.1', node_color = 'r', node_size = 100, alpha = 1)
    nx.draw_networkx_edges(G, pos,connectionstyle='arc3, rad = 0.1', edgelist = [(0,1)], width = 2, alpha = 0.5, edge_color='b')
    nx.draw_networkx_edges(G, pos,connectionstyle='arc3, rad = 0.1', edgelist= [(1,0)], width = 1, alpha = 1)
    plt.axis('off')
    plt.show() 
    

    See result here

提交回复
热议问题