Labeling edges in networkx

后端 未结 2 1499
耶瑟儿~
耶瑟儿~ 2020-12-29 05:26

I´m programming a basic neural network and want to plot it as a picture. For that i created all the nodes and edges i need.

    for l, j in zip(self.layers,         


        
2条回答
  •  情书的邮戳
    2020-12-29 05:40

    you can use the edge attributes of G

    nx.draw(G, with_labels=True, node_color='skyblue', edge_cmap=plt.cm.Blues, pos = pos)
    edge_labels = nx.get_edge_attributes(G,'edge') # key is edge, pls check for your case
    formatted_edge_labels = {(elem[0],elem[1]):edge_labels[elem] for elem in edge_labels} # use this to modify the tuple keyed dict if it has > 2 elements, else ignore
    nx.draw_networkx_edge_labels(G,pos,edge_labels=formatted_edge_labels,font_color='red')
    plt.show()
    

提交回复
热议问题