Skip to content

Instantly share code, notes, and snippets.

@mag5323
Last active October 4, 2015 23:09
Show Gist options
  • Save mag5323/e5ad752b0e7df52f586b to your computer and use it in GitHub Desktop.
Save mag5323/e5ad752b0e7df52f586b to your computer and use it in GitHub Desktop.
import json
from networkx import *
from networkx.readwrite import json_graph
# gnp_random_graph(Nodes, Probability for edge creation)
G = gnp_random_graph(10, 0.4)
Degrees = G.degree()
MaxDeg = max(Degrees, key=Degrees.get)
Neighbors = G.neighbors(MaxDeg)
JsonG = json_graph.node_link_data(G)
# Coloring max deg and it's neighbors
JsonG['nodes'][MaxDeg]['group'] = 1
for node in Neighbors:
JsonG['nodes'][node]['group'] = 1
json.dump(JsonG, open('output.json', 'w'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment