pythonnetworkxgephi

How to define attribute on networkx graph to export it to gephi viz shape


I am trying to create nodes and edges with different shape than default (disc for nodes and solid for edges).

I use the viz attribute for the color and it works, but I have no success with the shape. Here are some example for the code I use:

import networkx as nx

G=nx.MultiDiGraph()
G.add_nodes_from([1,2,3])
attr={1:{'viz':{'shape':'square'}}, 2:{'viz':{'shape':'disc'}}, 3:{'viz':{'shape':'diamond', 'color':{'r': 178, 'g': 34, 'b': 34, 'a': 0}}}}
nx.set_node_attributes(G, attr)

G.add_edge(1,2, id='ID1', Label='L', viz={'shape':'dashed', 'color':{'r': 178, 'g': 34, 'b': 34, 'a': 0}})
G.add_edge(2,3, id='ID2', label='l')

nx.write_gexf(G, 'g_test_shape' +'.gexf')

I am neither able to define the edge Label at networkx graph.


Solution

  • This is the solution. Not pythonic at all, but it works. You need to install a plugin in Gephi and add a col with int for the sides of the polygons:

    https://gephi.org/plugins/#/plugin/polygon-shaped-nodes