简体   繁体   English

来自python元组的NetworkX图形图

[英]NetworkX graph plot from python tuple

In my tuple new below: 在下面的新元组中:

how can I make the "string" with highest number to be the head node and other string names attached to with width = to their number. 我怎样才能使编号最高的“字符串”成为头节点,并在其编号上附加以width =附加的其他字符串名称。

new = (('COCH', 8), ('CAB', 4), ('VSNL', 7), ('ZNRF', 8), ('SLC12A1', 4), 
('APC', 16), ('LOC', 8), ('TRPM', 4), ('TNFRSF', 22))

In my tuple above, how to have highest number(22) "TNFRSF" to be the node, to which all other strings are attached. 在我上面的元组中,如何使最高数目(22)“ TNFRSF”成为所有其他字符串都附加到的节点。 With connection width being their respective number. 连接宽度是它们各自的数量。 For instance, 'COCH'connects to "TNFRSF" node with width = 8. 例如,“ COCH”连接到宽度为8的“ TNFRSF”节点。

import networkx as nx

new = (('COCH', 8), ('CAB', 4), ('VSNL', 7), ('ZNRF', 8), ('SLC12A1', 4), ('APC', 16), ('LOC', 8), ('TRPM', 4), ('TNFRSF', 22))
children = sorted(new, key=lambda x: x[1])
parent = children.pop()[0]

G = nx.Graph()
for child, weight in children: G.add_edge(parent, child, weight=weight)
width = list(nx.get_edge_attributes(G, 'weight').values())
nx.draw_networkx(G, width=width)

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

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