#http://perso.crans.org/aynaud/communities/
import community
import matplotlib.pyplot as plt
import networkx as nx

fh=open("/home/yerali/Dropbox/mio/mis_cursos/facebook/0.edges", 'rb')
G=nx.read_edgelist(fh)
fh.close()

print "numero de ejes " + repr(G.number_of_edges())
pos = nx.spring_layout(G)

partition = community.best_partition(G)
r=community.modularity(partition,G)

print r

#drawing
size = float(len(set(partition.values())))

count = 0.
for com in set(partition.values()) :
    count = count + 1.
    list_nodes = [nodes for nodes in partition.keys()
                                if partition[nodes] == com]
    nx.draw_networkx_nodes(G, pos, list_nodes, node_size = 20,
                                node_color = str(count / size))

#nx.draw_networkx_edges(G,pos, node_size=20)
plt.show()

