我想在Gephi中可视化我的networkx图。我的图具有以下两种类型的节点ntype="main"ntype="sub"

    [('organisation', {'ws': 347.9, 'ntype': 'main'}), ('employee', {'ws': 0, 'ntype': 'sub'}),
('minor_staff', {'ws': 0, 'ntype': 'sub'}), ('assets', {'ws': 0, 'ntype': 'sub'}),
('stocks', {'ws': 315.0, 'ntype': 'main'}), ('HR', {'ws': 0, 'ntype': 'sub'}),
('Director_board', {'ws': 0, 'ntype': 'sub'}), ('stakeholders', {'ws': 0.1, 'ntype': 'sub'}),
 ('stockmarket', {'ws': 488.5, 'ntype': 'main'}), ('events', {'ws': 0, 'ntype': 'sub'}),
 ('facilities', {'ws': 0, 'ntype': 'extended'})]


使用Gephi进行可视化时,我想将我的main节点显示为蓝色,将sub节点显示为灰色。

有什么特殊的方法可以将节点保存在networkx中,以便Gephi识别这些颜色代码?

最佳答案

这解决了我的问题

import networkx as nx
""" Create a graph with three nodes"""
G = nx.Graph()
G.add_node('red', ws=1.0, ntype = 'main')
G.add_node('green', ws=1.5, ntype = 'sub')
G.add_node('blue', ws=1.2, ntype = 'sub')

for item in G.nodes(data = True):
    if item[1]['ntype'] == 'main':
        G.node[item[0]]['viz'] = {'color': {'r': 255, 'g': 0, 'b': 0, 'a': 0}}
    elif item[1]['ntype'] == 'sub':
        G.node[item[0]]['viz'] = {'color': {'r': 0, 'g': 255, 'b': 0, 'a': 0}}

""" Write to GEXF """
# Use 1.2draft so you do not get a deprecated warning in Gelphi
nx.write_gexf(G, "file2.gexf", version="1.2draft")

关于python - 在Gephi中可视化networkx图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48160166/

10-12 17:27