繁体   English   中英

将一个图的节点连接到另一个图的节点

[英]Connecting nodes of one graph to a node of another graph

你知道如何将一个图的所有节点连接到另一个图的节点吗?

for node in messages:
    graph.add_edge(graph.nodes[22], node, label="channel_of")

消息是一个图,两个属于同一类型。 graph.nodes[22]是一个通道,返回节点,但不是作为节点本身,而是作为字典 这就是单个消息节点无法连接到通道的原因。 如何在通道和所有消息节点之间创建一条边?

提前谢谢了!

看来您应该创建另一个包含graphmessages图表的图表

messages = nx.empty_graph(10)
graph = nx.empty_graph(2)

space = nx.union(messages, graph, rename=('m-', 'c-'))

for node in messages:
    space.add_edge(f'c-{0}', f'm-{node}', label="channel_of")

nx.draw_networkx(space, with_labels=True,
                 node_size=400, node_color='#7d99f5', font_weight='bold')

在此处输入图像描述

暂无
暂无

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

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