Search code examples
pythonnetworkxgephi

Exporting node size from NetworkX to Gephi


I have a graph in NetworkX. I have:

nx.draw_networkx_nodes(G, pos, node_size=node_sizes, ax=ax0)

Exporting the file to Gephi:

nx.write_gexf(G, 'graph.gexf')

However, the node sizes aren't preserved in the export.

How can I achieve this?


Solution

  • Setting the size with NetworkX will just be ignored by Gephi. So, the best way to achieve this that I found was to set each node's size using an attribute on the 'viz' attribute.

    For example, to make all nodes size 200:

    for node in G.nodes():
        G.node[node]['viz'] = {'size': 200}