【发布时间】:2023-03-07 03:26:02
【问题描述】:
我的 print G.nodes(data=True) 输出是:
[('Bytes:\n620', {}), ('dIP:\n178.237.19.228', {}), ('sPort:\n2049', {}), ('sPort:\n60179', {}), ('sIP:\n16.37.97.29', {}), (153, {}), ('dPort:\n443', {}), ('dPort:\n80', {}), ('Packets:\n2', {}), ('Packets:\n1', {}), ('sPort:\n44492', {}), ('Bytes:\n100', {}), ('sIP:\n16.37.93.196', {}), ('dIP:\n178.237.17.97', {}), (188, {}), ('dIP:\n16.37.157.74', {}), ('sIP:\n16.37.97.222', {}), ('dIP:\n178.237.17.61', {}), ('sIP:\n16.37.97.17', {}), ('Bytes:\n46', {}), (224, {}), (227, {}), ('dPort:\n691', {}), ('dIP:\n104.131.44.62', {}), ('sPort:\n55177', {}), ('Protocol:\n6', {}), (120, {}), ('sPort:\n56326', {})]
如何使用 pos 变量手动设置节点的位置(坐标)?
提前谢谢你,
你好 :)
【问题讨论】:
-
根据您的其他问题stackoverflow.com/q/52987548/2966723 和stackoverflow.com/q/52971894/2966723,这不是您的代码遇到的问题。您已经定义了一个图表,并且您已经创建了
pos。然后,您尝试使用包含不在图中的节点的nodelist绘制图形,因为您在将节点添加到图形时更改了它们的名称。图中的所有节点都已经有了坐标[检查它-print(pos)]。问题是您的节点列表使用了 networkx 无法识别的不同名称。 -
或者以另一种方式呈现。运行代码
for node in nodelist: if node not in G.nodes: print('node {} will produce an error because it isn't a node of G.'.format(node))
标签: python set position nodes networkx