Created
July 25, 2011 16:47
-
-
Save drewconway/1104553 to your computer and use it in GitHub Desktop.
A short example for using the D3 export feature. Using Mike Dewar (@mikedewar) Twitter social graph :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
from networkx.readwrite import d3_js | |
mikedewar = nx.read_graphml('mikedewar_rec.graphml') | |
# We need to relabel nodes as Twitter name if we want to show the names in the plot | |
label_dict = dict(map(lambda i : (mikedewar.nodes()[i], mikedewar.nodes(data=True)[i][1]['Label']), xrange(mikedewar.number_of_nodes()))) | |
mikedewar_d3 = nx.relabel_nodes(mikedewar, label_dict) | |
# Export | |
d3_js.export_d3_js(mikedewar_d3, files_dir="mikedewar", graphname="mikedewar", group="REC", node_labels=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment