首页 > 解决方案 > 如何将子图添加到现有图作为 networkx 中的边?

问题描述

我正在尝试动态构建这样的图表:

@property
def graph(self):
    g = nx.DiGraph()
    g.add_node(self)
    for child in self.children_pivots:
        g = nx.compose(g, child.graph)
        g.add_edge(self, child)
    return g

其中 children_pivots 是与 self 相同对象类型的列表。似乎不支持此功能,或者我在文档中错过了它。我是否必须手动迭代组件并构建图表?有没有简单明了的方法可以说:这是一个图,将此图的根添加为由该边连接的新节点。

标签: pythonnetworkx

解决方案


推荐阅读