简体   繁体   中英

Python networkx: grouping nodes based on a node attribute

I am drawing a network topology diagram (Telecoms related) from an adjacency matrix. I have a numpy adjacency matrix from which I generate a networkx graph (G).

At a particular Site (City) I have multiple nodes, that may or may not be interconnected. The site name can be determined from the Node name (label).

Is it possible to cluster the nodes at the same site together (and ideally draw a box around them), while displaying the individual nodes within the site? I consider this like grouping nodes based on some node attribute such as node name.

I the diagram Site A shows the desired output for the diagram. Example graph

I believe I could get a solution if I created dummy edges between nodes at the same site, and gave them a high weight using spring layout to ensure the same nodes at a site are close together, however this does not seem like an optimum solution.

Any advice appreciated!! Thanks in Advance. Also note it is not essential to use numpy, networkx I am open to suggestions.

I've been dealing with a similar problem recently. My solution was to create a dummy graph, where node properties were the new nodes, and edges among the new nodes were weighted based on the number of connections between individual node types.

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