In [1]:
import networkx as nx
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline

In [2]:
G = nx.read_gpickle('20150902_all_ird Final Graph.pkl')

In [3]:
# Number of edges
n_edges = len(G.edges())
n_edges


Out[3]:
25683

In [4]:
# Number of nodes
n_nodes = len(G.nodes())
n_nodes


Out[4]:
18632

In [5]:
# Sparsity of the graph
n_edges / n_nodes**2


Out[5]:
7.39821248724015e-05

In [6]:
pwis = [d['pwi'] for sc, sk, d in G.edges(data=True)]
plt.hist(pwis)


Out[6]:
(array([  4.00000000e+00,   5.00000000e+00,   0.00000000e+00,
          1.60000000e+01,   5.10000000e+01,   6.50000000e+01,
          2.80000000e+02,   3.82900000e+03,   3.71700000e+03,
          1.77160000e+04]),
 array([ 6.941187 ,  7.0470683,  7.1529496,  7.2588309,  7.3647122,
         7.4705935,  7.5764748,  7.6823561,  7.7882374,  7.8941187,  8.       ]),
 <a list of 10 Patch objects>)

In [10]:
np.median(pwis)


Out[10]:
7.9811279999999991

In [13]:
(8 - np.median(pwis)) / 8 * 100


Out[13]:
0.2359000000000111

In [15]:
np.median(pwis) / 8 * 100


Out[15]:
99.764099999999985

In [8]:
# Plot PWI distribution
from collections import defaultdict

seg_pwis = defaultdict(list)

for sc, sk, d in G.edges(data=True):
    for s, p in d['segments'].items():  # s: segment, p: pwi
        seg_pwis[s].append(p)

In [9]:
for s, ps in seg_pwis.items():
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.hist(ps)
    ax.set_title('Segment {0}, Min {1} Max{2}'.format(s, min(ps), max(ps)))



In [ ]: