简体   繁体   中英

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.

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

It seems that it is not possible. This is what I found at Gephi forum:

Gephi does not support other shapes than circles for the moment.

The answer is from 2018.

Regards,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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