简体   繁体   中英

Using networkx to create node labels from an array

I have some nodes that are being generated from a numpy adjacency matrix. I also have an array of labels for said nodes already where node 0 in the matrix corresponds to label 0 in the array. What is the easiest way to apply those labels to the nodes in the graph?

You can specify the labels while drawing but you must first convert the array into a dictionary where the key value is the node number and the value is the label. After whuch you can specify labels with the label argument like so:

nx.draw(G, labels=labelDict)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM