pythonigraphgml

Use leidenalg and igraph to find cluster and then output gml file


import leidenalg as la

import igraph as ig

G = ig.Graph.Famous('Zachary')

partition = la.find_partition(G, la.ModularityVertexPartition)

ig.plot(partition,vertex_size = 30)

ig.save(G,'ttt.gml')

Everything works fine, however ig.save does not contain cluster information, just nodes and edges. Need to add Cluster information to nodes in ttt.gml file


Solution

  • The graph itself doesn't contain any information of the partition. You should first add this information to the graph before saving it by doing G.vs['cluster'] = partition.membership.