Визуализируйте граф networkx в Gephi

Я хочу визуализировать свой график networkx в Gephi. В моем графике есть два типа узлов 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 идентифицировал эти цветовые коды?


person J Cena    schedule 09.01.2018    source источник
comment
stackoverflow.com/questions/28522155/ Попробовать?   -  person Tai    schedule 09.01.2018


Ответы (1)


Это решило мою проблему

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")
person J Cena    schedule 09.01.2018