3. Stanford Large Network Dataset Collection
http://snap.stanford.edu/data/index.html
Name Type Nodes Edges Description
ego-Facebook Undirected 4,039 88,234 Social circles from Facebook (anonymized)
ego-Gplus Directed 107,614 13,673,453 Social circles from Google+
ego-Twitter Directed 81,306 1,768,149 Social circles from Twitter
soc-Epinions1 Directed 75,879 508,837 Who-trusts-whom network of Epinions.com
soc-LiveJournal1 Directed 4,847,571 68,993,773 LiveJournal online social network
soc-Pokec Directed 1,632,803 30,622,564 Pokec online social network
soc-Slashdot0811 Directed 77,360 905,468 Slashdot social network from November 2008
soc-Slashdot0922 Directed 82,168 948,464 Slashdot social network from February 2009
wiki-Vote Directed 7,115 103,689 Wikipedia who-votes-on-whom network
wiki-RfA Directed, Signed 10,835 159,388 Wikipedia Requests for Adminship (with text)
Social networks
8. Example of generators
Parameters: r : int
Branching factor of the tree
h : int
Height of the tree
create_using : NetworkX graph type, optional
Use specified type to construct graph (default = networkx.Graph)
Returns: G : networkx Graph
A tree with n nodes
balanced_tree
balanced_tree(r, h, create_using=None) [source]
Return the perfectly balanced r-tree of height h.
G = balanced_tree(2, 2)
11. Generating JSON
JSON
Generate and parse JSON serializable data for NetworkX graphs.
These formats are suitable for use with the d3.js examples http://d3js.org/
import json
from networkx import *
from networkx.readwrite import json_graph
G = balanced_tree(2, 2)
# Return data in node-link format that is suitable for JSON serialization.
JsonG = json_graph.node_link_data(G)
# Writing JsonG to output.json by python's native json encoder.
json.dump(JsonG, open('output.json', 'w'))
12. Rendering HTML
index.html
<head>
<title>Force-Directed Layout</title>
<script src=“//cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js”></script>
<link type="text/css" rel="stylesheet" href="force.css"/>
</head>
<body>
<div id="chart"></div>
<script src="force.js"></script>
</body>
var vis = d3.select("#chart")
.append("svg:svg")
.attr("width", w).attr("height", h);
d3.json("output.json", function(json) {
var force = d3.layout.force()
.charge(-120)
.linkDistance(30)
.nodes(json.nodes)
.links(json.links)
.size([w, h])
.start();
force.js
Github example
D3.js force-directed layout