PyNetViz(Python Network Visualization 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
This is a demo for independent gexf, html file. In this case, IPython Notebook Viewer well work.
In [1]:
import networkx as nx
import pynetviz.sigmajs as nvs # pip install pynetviz
In [8]:
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, filename='./1.gexf')
nvs.make_html(drawEdges='true', gexfname='./1.gexf', filename='./1.html')
nvs.view_html(filename='./1.html')
In [9]:
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, filename='./2.gexf')
nvs.make_html(drawEdges='true', gexfname='./2.gexf', filename='./2.html')
nvs.view_html(filename='./2.html')
In [10]:
G = nx.karate_club_graph()
In [11]:
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 [12]:
layout = nx.spring_layout(G)
nvs.make_gexf(G, layout, filename='./3.gexf')
nvs.make_html(drawEdges='true', gexfname='./3.gexf', filename='./3.html')
nvs.view_html(height=1000, filename='./3.html')
In [13]:
layout = nx.spectral_layout(G)
nvs.make_gexf(G, layout, filename='./4.gexf')
nvs.make_html(drawEdges='true', gexfname='./4.gexf', filename='./4.html')
nvs.view_html(height=1000, filename='./4.html')
In [14]:
nvs.make_gexf(G, layout, filename='./5.gexf')
nvs.make_html(drawEdges='true', gexfname='./5.gexf', filename='./5.html')
nvs.view_html(height=300, filename='./5.html')
In [15]:
nvs.make_gexf(G, layout, filename='./6.gexf')
nvs.make_html(drawEdges='false', gexfname='./6.gexf', filename='./6.html')
nvs.view_html(height=300, filename='./6.html')
In [16]:
nx.degree_centrality(G)
Out[16]:
In [17]:
layout = nx.spring_layout(G)
nvs.make_gexf(G, layout, size=nx.degree_centrality(G), filename='./7.gexf')
nvs.make_html(drawEdges='true', gexfname='./7.gexf', filename='./7.html')
nvs.view_html(height=500, filename='./7.html')
In [18]:
nvs.make_gexf(G, layout, size=nx.betweenness_centrality(G), filename='./8.gexf')
nvs.make_html(drawEdges='true', gexfname='./8.gexf', filename='./8.html')
nvs.view_html(height=500, filename='./8.html')
In [19]:
nvs.make_gexf(G, layout, size=nx.closeness_centrality(G), filename='./9.gexf')
nvs.make_html(drawEdges='true', gexfname='./9.gexf', filename='./9.html')
nvs.view_html(height=500, filename='./9.html')
In [20]:
nvs.make_gexf(G, layout, size=nx.clustering(G), filename='./10.gexf')
nvs.make_html(drawEdges='true', gexfname='./10.gexf', filename='./10.html')
nvs.view_html(height=500, filename='./10.html')
In [21]:
nvs.make_gexf(G, layout, size=[c*10 for c in nx.degree_centrality(G)], filename='./11.gexf')
nvs.make_html(drawEdges='true', gexfname='./11.gexf', filename='./11.html')
nvs.view_html(height=500, filename='./11.html')
In [ ]: