Bipartite graph in NetworkX

前端 未结 3 1613
攒了一身酷
攒了一身酷 2020-12-01 15:02
B.add_nodes_from(a, bipartite=1)
B.add_nodes_from(b, bipartite=0)
nx.draw(B, with_labels = True)  
plt.savefig(\"graph.png\")

I am getting the foll

3条回答
  •  情深已故
    2020-12-01 15:34

    Another example, combining graph with bipartite graph:

    G = nx.read_edgelist('file.txt', delimiter="\t")
    aux = G.edges(data=True)
    B = nx.Graph()
    B.add_nodes_from(list(employees), bipartite=0)
    B.add_nodes_from(list(movies), bipartite=1)
    B.add_edges_from(aux)
    
    %matplotlib notebook
    import [matplotlib][1].pyplot as plt
    plt.figure()
    
    edges = B.edges()
    print(edges)
    X, Y = bipartite.sets(B)
    pos = dict()
    pos.update( (n, (1, i)) for i, n in enumerate(X) ) # put nodes from X at x=1
    pos.update( (n, (2, i)) for i, n in enumerate(Y) ) # put nodes from Y at x=2
    nx.draw_networkx(B, pos=pos, edges=edges)
    plt.show()
    

提交回复
热议问题