简体   繁体   English

Python networkx:基于节点属性对节点进行分组

[英]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). 我有一个numpy邻接矩阵,我从中生成一个networkx图(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. 我的图表Site A显示了图表所需的输出。 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. 另请注意,使用numpy,networkx并不是必不可少的,我愿意接受建议。

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. 我的解决方案是创建一个虚拟图,其中节点属性是新节点,新节点之间的边根据各个节点类型之间的连接数加权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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