Revision 05763cfb util/MyUtil.py
util/MyUtil.py  

3  3 
import networkx as nx 
4  4 
import random as rnd 
5  5 
import matplotlib.pyplot as plt 
6 
plt.ion() 

6  
7  7 
import matplotlib.colors as mcolors 
8  8 
import sys 
9  9 
import code # code.interact(local=dict(globals(), **locals())) 
10  10  
11 
def draw(G, pos, xmax, ymax, measures=None): 

11 
def draw(G, pos, xmax, ymax, measures=None, saveFig=False, path=None): 

12 
fig = plt.figure() 

12  13 
lay = {k:pos[k] for k in range(0,len(pos))} 
13  14 
if not measures: 
14 
measures = nx.betweenness_centrality(G, normalized = False, weight = 'weight', endpoints=True) 

15 
measures = nx.betweenness_centrality(G, normalized = True, weight = 'weight', endpoints=True) 

16  
15  17 
measure_name = "Betweenness" 
16 
nodes = nx.draw_networkx_nodes(G, lay, node_size=25, cmap=plt.cm.gnuplot2, 

17 
node_color=measures.values(), 

18 
nodelist=measures.keys()) 

19 
nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1)) 

18  
19 
nodes = nx.draw_networkx_nodes(G, lay, node_size=50, cmap=plt.cm.Spectral, 

20 
node_color=measures.values(), 

21 
nodelist=measures.keys()) 

22  
23 
#nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1)) 

24 
mes=measures.values() 

25 
nodes.set_norm(mcolors.LogNorm(vmin=0.001, vmax=max(mes))) 

26 
#nodes.set_norm(mcolors.LogNorm()) 

20  27  
21  28 
edges = nx.draw_networkx_edges(G, lay) 
22  29 
plt.title(measure_name) 
23 
plt.colorbar(nodes) 

24  30  
31 
myticks=np.geomspace(start=0.001, stop=max(mes), num=7) 

32 
cbar=plt.colorbar(nodes, ticks=myticks, label='Norm BC') 

33 
cbar.ax.set_yticklabels(["{0:0.4f}".format(i) for i in myticks]) 

34 
#plt.colorbar(ticks=range(6), label='digit value') 

35 
#plt.clim(0.5, 5.5) 

25  36 
plt.xlim(0, xmax) 
26  37 
plt.ylim(0, ymax) 
27 


28 
plt.draw() 

29 
plt.pause(0.01) 

30 
plt.clf() 

31 
#plt.show() 

38 
plt.xticks(range(0,105,5)) 

39 
plt.yticks(range(0,105,5)) 

40 
plt.grid(which='both') 

41 
if not saveFig: 

42 
plt.ion() 

43 
plt.draw() 

44 
plt.pause(0.01) 

45 
plt.clf() 

46 
else: 

47 
fig.savefig(path, format='pdf') 

48 
#plt.clf() 

49 
#plt.show() 

32  50  
33  51 
def dictAlikes(d1, d2, perc): 
34  52 
if (sorted(d1.keys()) != sorted(d2.keys())): 
Also available in: Unified diff