PyNetViz(Python Network Vizualization for Sigma.js) as nvs

Author: Kyunghoon Kim ( kyunghoon@unist.ac.kr )
Date created: 10/06/2015
Date last modified: 10/06/2015
Python Version: 2.7

In [20]:
import networkx as nx
import pynetviz.sigmajs as nvs # pip install pynetviz

Basic Network Draw

Random layout


In [19]:
G = nx.Graph()
G.add_edges_from([(1,2),(2,3),(3,4),(5,6)])
G.add_edge(1, 3)
G.add_edge(1, 6)
nvs.make_gexf(G)
nvs.make_html(drawEdges='true')
nvs.view_html()


Spring Layout


In [6]:
G = nx.Graph()
G.add_edges_from([(1,2),(2,3),(3,4),(5,6)])
G.add_edge(1, 3)
G.add_edge(1, 6)
layout = nx.spring_layout(G)
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='true')
nvs.view_html()


Example. Karate club

Network Information


In [7]:
print "Number of Nodes : ", nx.number_of_nodes(G)
print "Number of Edges : ", nx.number_of_edges(G)
degreelist = list(G.degree().values())
print "Avg. Node Degree : ", float(sum(degreelist))/nx.number_of_nodes(G)
try:
    print "Avg. Path Length : ", nx.average_shortest_path_length(G)
except nx.NetworkXError as e:
    print e
print "Avg. Clustering Coefficient : ", nx.average_clustering(G)


Number of Nodes :  6
Number of Edges :  6
Avg. Node Degree :  2.0
Avg. Path Length :  1.93333333333
Avg. Clustering Coefficient :  0.277777777778

Change a height of iframe


In [9]:
G = nx.karate_club_graph()
layout = nx.spring_layout(G)
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='true')
nvs.view_html(height=1000)


Change a layout using spectral_layout


In [10]:
layout = nx.spectral_layout(G)
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='true')
nvs.view_html(height=1000)


Change a height of iframe


In [11]:
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='true')
nvs.view_html(height=300)


Disable for edge


In [12]:
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='false')
nvs.view_html(height=300)


Degree Centrality


In [13]:
nx.degree_centrality(G)


Out[13]:
{0: 0.48484848484848486,
 1: 0.2727272727272727,
 2: 0.30303030303030304,
 3: 0.18181818181818182,
 4: 0.09090909090909091,
 5: 0.12121212121212122,
 6: 0.12121212121212122,
 7: 0.12121212121212122,
 8: 0.15151515151515152,
 9: 0.06060606060606061,
 10: 0.09090909090909091,
 11: 0.030303030303030304,
 12: 0.06060606060606061,
 13: 0.15151515151515152,
 14: 0.06060606060606061,
 15: 0.06060606060606061,
 16: 0.06060606060606061,
 17: 0.06060606060606061,
 18: 0.06060606060606061,
 19: 0.09090909090909091,
 20: 0.06060606060606061,
 21: 0.06060606060606061,
 22: 0.06060606060606061,
 23: 0.15151515151515152,
 24: 0.09090909090909091,
 25: 0.09090909090909091,
 26: 0.06060606060606061,
 27: 0.12121212121212122,
 28: 0.09090909090909091,
 29: 0.12121212121212122,
 30: 0.12121212121212122,
 31: 0.18181818181818182,
 32: 0.36363636363636365,
 33: 0.5151515151515151}

Change of a node size with degree centrality


In [14]:
layout = nx.spring_layout(G)
nvs.make_gexf(G, layout, size=nx.degree_centrality(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)


Change of a node size with betweenness centrality


In [15]:
nvs.make_gexf(G, layout, size=nx.betweenness_centrality(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)


Change of a node size with closeness centrality


In [16]:
nvs.make_gexf(G, layout, size=nx.closeness_centrality(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)


Change of a node size with clustering coefficient


In [17]:
nvs.make_gexf(G, layout, size=nx.clustering(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)


Change of a node size * 10 with degree centrality


In [18]:
nvs.make_gexf(G, layout, size=[c*10 for c in nx.degree_centrality(G)])
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)



In [ ]: