def draw_to_browser(agents): data1 = {} data2= [] for i in range(0,250): #param for j in range(20): #print graphStrings[i] G = create_graph_of_agent(agents[str(i)][str(j)]) d = json_graph.node_link_data(G) d["directed"] = 1 d["multigraph"] = 1 text= "s " +str(i + 1)+" | " + str(j + 1) data1[text] = d data2.append({"text": text, "value": text}) data = {"0": data1, "codes": data2} write_html(data) json.dump(data, open('IPD_output/data.json', 'w')) print('Wrote node-link JSON data to temp.json') # open URL in running web browser http_server.load_url('IPD_output/overall.html') print('Or copy all files to webserver and load graph.html')
def draw_to_browser(agents): data1 = {} data2 = [] for i in range(0, 250): #param for j in range(20): #print graphStrings[i] G = create_graph_of_agent(agents[str(i)][str(j)]) d = json_graph.node_link_data(G) d["directed"] = 1 d["multigraph"] = 1 text = "s " + str(i + 1) + " | " + str(j + 1) data1[text] = d data2.append({"text": text, "value": text}) data = {"0": data1, "codes": data2} write_html(data) json.dump(data, open('IPD_output/data.json', 'w')) print('Wrote node-link JSON data to temp.json') # open URL in running web browser http_server.load_url('IPD_output/overall.html') print('Or copy all files to webserver and load graph.html')
def render_network(network): # write json formatted data d = json_graph.node_link_data(network) # node-link format to serialize # write json json.dump(d, open('force/force.json','w')) # open URL in running web browser fileName = os.path.join(os.path.dirname(__file__), 'force/force.html') http_server.load_url(fileName)
def draw(self): for n in self.graph: self.graph.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data(self.graph) # node-link format to serialize # write json json.dump(d, open('force/force.json', 'w')) print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/force.html') print('Or copy all files in force/ to webserver and load force/force.html')
def main(): g=net.Graph() #read_lj_friends(g,'kozel_na_sakse') snowball_sampling(g,'justinbieber') for n in g: g.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data(g) # node-link format to serialize # write json json.dump(d, open('force/force.json','w')) http_server.load_url('force/force.html')
def draw(self): for n in self.graph: self.graph.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data( self.graph) # node-link format to serialize # write json json.dump(d, open('force/force.json', 'w')) print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/force.html') print( 'Or copy all files in force/ to webserver and load force/force.html' )
def force_graph(G): # G = nx.barbell_graph(6,3) # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node # for n in G: # G.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data(G) # node-link format to serialize # write json json.dump(d, open('force/force.json','w')) print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/force.html') print('Or copy all files in force/ to webserver and load force/force.html')
def drawGraph(graph, is_connected=False): print 'Nodes: %s' % graph.order() print 'Links: %s' % graph.size() connected_str = "_connected" if is_connected else "" outputfile = os.path.join(os.getcwd(), 'guifiAnalyzerOut', 'd3', str(root) + corename + connected_str + '.json') #outputgexf = os.path.join( os.getcwd(), 'guifiAnalyzerOut', # 'results', str(root)+corename+connected_str+'.gexf') #networkx.write_gexf(graph, outputgexf) # For undirected d = json_graph.node_link_data(graph) json.dump(d, open(outputfile, 'w')) # For directed #save(graph,outputfile) html = os.path.join(os.getcwd(), 'guifiAnalyzerOut', 'd3', 'test.html') #http_server.load_url(html) http_server.load_url('guifiAnalyzerOut/d3/test.html')
def drawGraph(graph, is_connected=False): print 'Nodes: %s' % graph.order() print 'Links: %s' % graph.size() connected_str = "_connected" if is_connected else "" outputfile = os.path.join( os.getcwd(), 'guifiAnalyzerOut', 'd3', str(root)+corename+connected_str+'.json') #outputgexf = os.path.join( os.getcwd(), 'guifiAnalyzerOut', # 'results', str(root)+corename+connected_str+'.gexf') #networkx.write_gexf(graph, outputgexf) # For undirected d = json_graph.node_link_data(graph) json.dump(d, open(outputfile, 'w')) # For directed #save(graph,outputfile) html = os.path.join( os.getcwd(), 'guifiAnalyzerOut', 'd3', 'test.html') #http_server.load_url(html) http_server.load_url('guifiAnalyzerOut/d3/networks.html')
def toy_graph(): G = nx.DiGraph() for i in range(1, 1000): tree = list(set(list(int_to_list(random.randint(1, i))))) # Add the entire sequence to the tree for j in range(0, len(tree) - 1): G.add_edge(tree[j], tree[j + 1]) for n in G: G.node[n]['name'] = n d = json_graph.node_link_data(G) json.dump(d, open('graph/graph.json', 'w')) # The http_server is just a short piece of code that used to be in the # examples directory of the networkx library. http_server.load_url('graph/graph.html')
def draw_to_browser(agents, stats): # print "# of strings" # print len(graphStrings) draw_sim_charts(stats) data1 = {} data2= [] for i in range(len(agents)): #print graphStrings[i] G = create_graph_of_agent(agents[i]) d = json_graph.node_link_data(G) d["directed"] = 1 d["multigraph"] = 1 data1[str(i + 1)] = d j1, j2 = round(agents[i].joss_ann[0], 4), round(agents[i].joss_ann[1], 4) jay1, jay2 = j1, j2 if j1 + j2 > 1: jay1, jay2 = (1 - j2, 1 - j1) text = str(i + 1) #+ " - (" + str(jay1) + "," + str(jay2) + ")" data2.append({"text": text, "value": str(i + 1)}) # print d data = {"0": data1, "codes": data2} # print json_list # print len(json_list) json_list = json.dumps(data) # node-link format to serialize # print d # write json write_html(data) json.dump(data, open('IPD_output/data.json', 'w')) print('Wrote node-link JSON data to temp.json') # open URL in running web browser http_server.load_url('IPD_output/graph009.html') print('Or copy all files to webserver and load graph.html')
"""Example of writing JSON format graph data and using the D3 Javascript library to produce an HTML/Javascript drawing. """ # Author: Aric Hagberg <*****@*****.**> # Copyright (C) 2011-2016 by # Aric Hagberg <*****@*****.**> # Dan Schult <*****@*****.**> # Pieter Swart <*****@*****.**> # All rights reserved. # BSD license. import json import networkx as nx from networkx.readwrite import json_graph import http_server G = nx.barbell_graph(6, 3) # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node for n in G: G.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data(G) # node-link format to serialize # write json json.dump(d, open('force/force.json', 'w')) print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/force.html') print('Or copy all files in force/ to webserver and load force/force.html')
# verts=dist.keys() # for d in sorted(verts): # print('%s %d' % (d,dist[d])) #print("radius: %d" % radius(G)) #print("diameter: %d" % diameter(G)) #print("eccentricity: %s" % eccentricity(G)) #print("center: %s" % center(G)) #print("periphery: %s" % periphery(G)) #print("density: %s" % density(G)) # draw_shell(G,with_labels=True) # plt.show() # write_gexf(G,"test.gexf") #write_pajek(G, "test.net") d = json_graph.node_link_data(G) outputfile = os.path.join( os.path.dirname( os.path.abspath(__file__)), 'd3', 'test.json') json.dump(d, open(outputfile, 'w')) html = os.path.join( os.path.dirname( os.path.abspath(__file__)), 'd3', 'test.html') http_server.load_url('d3/test.html')
"""Example of writing JSON format graph data and using the D3 Javascript library to produce an HTML/Javascript drawing. """ # Copyright (C) 2011-2012 by # Aric Hagberg <*****@*****.**> # Dan Schult <*****@*****.**> # Pieter Swart <*****@*****.**> # All rights reserved. # BSD license. __author__ = """Aric Hagberg <*****@*****.**>""" import json import networkx as nx from networkx.readwrite import json_graph import http_server G = nx.barbell_graph(6, 3) # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node for n in G: G.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data(G) # node-link format to serialize # write json json.dump(d, open('force/force.json', 'w')) print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/index.html') print('Or copy all files in force/ to webserver and load force/force.html')
#!/usr/bin/env python import http_server import os os.system("./parser") http_server.load_url('test1.html')
"""Example of writing JSON format graph data and using the D3 Javascript library to produce an HTML/Javascript drawing. """ # Copyright (C) 2011-2012 by # Aric Hagberg <*****@*****.**> # Dan Schult <*****@*****.**> # Pieter Swart <*****@*****.**> # All rights reserved. # BSD license. __author__ = """Aric Hagberg <*****@*****.**>""" import json import networkx as nx from networkx.readwrite import json_graph import http_server G = nx.barbell_graph(6,3) # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node for n in G: G.node[n]['name'] = n # write json formatted data d = json_graph.node_link_data(G) # node-link format to serialize # write json json.dump(d, open('force/force.json','w')) print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/index.html') print('Or copy all files in force/ to webserver and load force/force.html')
import http_server # open URL in running web browser http_server.load_url('force/soccer.html')
"""Example of writing JSON format graph data and using the D3 Javascript library to produce an HTML/Javascript drawing. """ # Copyright (C) 2011-2012 by # Aric Hagberg <*****@*****.**> # Dan Schult <*****@*****.**> # Pieter Swart <*****@*****.**> # All rights reserved. # BSD license. __author__ = """Aric Hagberg <*****@*****.**>""" import json import networkx as nx from networkx.readwrite import json_graph import http_server G = nx.barbell_graph(6, 3) # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node for n in G: G.node[n]["name"] = n # write json formatted data d = json_graph.node_link_data(G) # node-link format to serialize # write json json.dump(d, open("force/force.json", "w")) print("Wrote node-link JSON data to force/force.json") # open URL in running web browser http_server.load_url("force/force.html") print("Or copy all files in force/ to webserver and load force/force.html")
dist[p] += 1 else: dist[p] = 1 print('') # print("length #paths") # verts=dist.keys() # for d in sorted(verts): # print('%s %d' % (d,dist[d])) #print("radius: %d" % radius(G)) #print("diameter: %d" % diameter(G)) #print("eccentricity: %s" % eccentricity(G)) #print("center: %s" % center(G)) #print("periphery: %s" % periphery(G)) #print("density: %s" % density(G)) # draw_shell(G,with_labels=True) # plt.show() # write_gexf(G,"test.gexf") #write_pajek(G, "test.net") d = json_graph.node_link_data(G) outputfile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'd3', 'test.json') json.dump(d, open(outputfile, 'w')) html = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'd3', 'test.html') http_server.load_url('d3/test.html')
#!/usr/bin/env Python import http_server if __name__ == '__main__': http_server.load_url('force.html')
G = nx.read_gpickle('metagraph5') # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node for n in G.nodes(data=True): n[1]['name'] = n[1]['Type'] H = nx.convert_node_labels_to_integers(G) # write json formatted data d = json_graph.node_link_data(H) # node-link format to serialize # write json json.dump(d, open('force/graph5.json','w')) G = nx.read_gpickle('metagraph5_reduced') # this d3 example uses the name attribute for the mouse-hover value, # so add a name to each node for n in G.nodes(data=True): n[1]['name'] = n[1]['Type'] H = nx.convert_node_labels_to_integers(G) # write json formatted data d = json_graph.node_link_data(H) # node-link format to serialize # write json json.dump(d, open('force/graph5-r.json','w')) ''' print('Wrote node-link JSON data to force/force.json') # open URL in running web browser http_server.load_url('force/metagraph5.html') print('Or copy all files in force/ to webserver and load force/force.html')