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
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()
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()
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)
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)
In [10]:
layout = nx.spectral_layout(G)
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='true')
nvs.view_html(height=1000)
In [11]:
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='true')
nvs.view_html(height=300)
In [12]:
nvs.make_gexf(G, layout)
nvs.make_html(drawEdges='false')
nvs.view_html(height=300)
In [13]:
nx.degree_centrality(G)
Out[13]:
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)
In [15]:
nvs.make_gexf(G, layout, size=nx.betweenness_centrality(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)
In [16]:
nvs.make_gexf(G, layout, size=nx.closeness_centrality(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)
In [17]:
nvs.make_gexf(G, layout, size=nx.clustering(G))
nvs.make_html(drawEdges='true')
nvs.view_html(height=500)
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 [ ]: