Statistics
| Branch: | Revision:

mobicen / varie / util / MyUtil.py @ 9110387b

History | View | Annotate | Download (1.13 KB)

1
from prettytable import PrettyTable
2
import numpy as np
3
import networkx as nx 
4
import matplotlib.pyplot as plt
5
import matplotlib.colors as mcolors
6
import sys
7

    
8
def draw(G, measures, measure_name):
9
    pos=nx.spring_layout(G)
10
    nodes = nx.draw_networkx_nodes(G, pos, node_size=250, cmap=plt.cm.gnuplot2, 
11
                                   node_color=measures.values(),
12
                                   nodelist=measures.keys())
13
    nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1))
14
    
15
    # labels = nx.draw_networkx_labels(G, pos)
16
    edges = nx.draw_networkx_edges(G, pos)
17

    
18
    plt.title(measure_name)
19
    plt.colorbar(nodes)
20
    plt.axis('off')
21
    plt.show()
22

    
23
def summary(v):
24
    vmin=min(v)
25
    vmax=max(v)
26
    tot=sum(v)
27
    avg=np.mean(v)
28
    std=np.std(v)
29
    t = PrettyTable(['min','max', 'mean','std','tot'])
30
    t.add_row([vmin,vmax,avg,std,tot])
31
    print t
32
    return avg, std, vmax, vmin, tot
33

    
34
if __name__ == "__main__":
35
    topo = sys.argv[1]
36
    G = nx.read_weighted_edgelist(topo, create_using = nx.Graph())
37
    load_indexes = nx.load_centrality(G, normalized = False, weight = 'weight')
38
    draw(G,load_indexes, "Load")