Networkx: Overlapping edges when visualizing MultiGraph

前端 未结 4 1912
迷失自我
迷失自我 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:07

    Well I know its probably not what you're looking for, but I was facing a similar problem where I wanted to have a directed graph where the edge between two nodes had a different weight depending on the direction (whether it was going into or out of the node) and the work around I did was I used a different color for each edge and decreased the opacity for one of them so it would show even if they overlap. I only needed two edges between my two nodes so it did the trick for me.

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

提交回复
热议问题