Пример #1
0
import zen
import d3js
import random
import math
from time import sleep

G = zen.generating.erdos_renyi(100, 0.03)
#G = zen.io.gml.read('2013-actor-actor.gml')
#G = zen.io.edgelist.read('japanese.edgelist', ignore_duplicate_edges=True)
print G.num_edges

d3 = d3js.D3jsRenderer(G,
                       event_delay=0.03,
                       interactive=False,
                       node_dstyle=d3js.node_style(size=4),
                       node_hstyle=d3js.node_style(fill='#EB4343'),
                       edge_hstyle=d3js.edge_style(stroke='#EB4343',
                                                   stroke_width=5))

d3.update()
sleep(2)

# make the visualization update after every step
d3.set_interactive(True)

d3.set_title('Positioning Nodes...')
for nidx in G.nodes_iter_():
    x = 250 + 230 * math.cos(math.radians(360.0 * nidx / G.num_nodes))
    y = 300 + 150 * math.sin(math.radians(360.0 * nidx / G.num_nodes))
    d3.position_node(nidx, x, y)
                d3.clear_highlights()
                d3.highlight_nodes_(list(where(x>0)[0]))
            else:
                d3.highlight_nodes_(list(where(cum_highlighted>0)[0]))
            d3.update()
        d3.set_interactive(interactive)
        if keep_highlights:
            return cum_highlighted
        else:
            return x



## Visualize
G = zen.io.gml.read('bible.gml')
d3 = d3js.D3jsRenderer(G, event_delay=0.1, interactive=False, autolaunch=True)

y=zeros(G.num_nodes)
y[1] = 1

propagate(G,d3,y,10,slp = 1)

#d3 = d3js.D3jsRenderer(G, event_delay=0.1, interactive=False, autolaunch=False)
d3.update()
sleep(1)
'''
dt = 0.05 # the "infintesimal" size steps we take to integrate
T = 6 # the end of the simulation time
time = linspace(0,T,int(T/dt)) # the array of time points spaced by dt

Пример #3
0
sys.path.append('../zend3js/')
import d3js
import csv
import progressbar
import numpy.linalg as la
import matplotlib.pyplot as plt
from scipy.linalg import solve

G = zen.Graph()
f = open('output_new.csv')
csv_f = csv.reader(f)

row = [r for r in csv_f]

for i in range(0, len(row)):

    first = row[i][0]
    second = row[i][1]
    weight_1 = row[i][2]

    if (float(weight_1) != 0):
        G.add_edge(first, second, weight=float(weight_1))
##
zen.io.gml.write(G, 'Billion.gml')

d3 = d3js.D3jsRenderer(G, interactive=False, autolaunch=True)
d3.clear()
G = zen.io.gml.read('Billion.gml', directed=False)
d3.set_graph(G)
d3.update()