-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotting.py
59 lines (44 loc) · 1.79 KB
/
plotting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
def plot_entropies(entropies, s_list):
"""
Utility function to plot entropies as a function of time steps
"""
colors = ['blue', 'red', 'black', 'yellow', 'orange', 'green', 'grey',
'brown']
for i in s_list:
# plot entropies Vs temporal indexes
hs1 = entropies[i]
_ = plt.plot(hs1, label="clique " + str(i), color=colors[i % len(colors)])
plt.xticks()
plt.title('Entropy profiles of different cliques')
plt.legend()
return
def plot_network_diffusion(G, pos, node_vector=None, edge_vector=None,
node_labels=False, edge_labels=False):
# Find edge labels
l_e = list(G.edges)
e = dict((tuple(sorted(l_e[x])), x) for x in range(0, len(l_e)))
e_labels = {tuple(x): 'e' + str(y) for x, y in e.items()}
if edge_vector is not None:
colors_edge = np.squeeze(np.asarray(edge_vector))
_ = nx.draw_networkx_edges(G, pos, edge_color=colors_edge,
width=3, with_labels=False)
else:
_ = nx.draw_networkx_edges(G, pos, edge_color="gray",
width=2, with_labels=False)
if node_vector is not None:
colors_node = np.squeeze(np.asarray(node_vector))
_ = nx.draw_networkx_nodes(G, pos, node_color=colors_node,
with_labels=False, node_size=500)
else:
_ = nx.draw_networkx_nodes(G, pos, node_color="blue",
with_labels=False, node_size=500)
if edge_labels:
_ = nx.draw_networkx_edge_labels(G, pos, e_labels, alpha=1)
if node_labels:
_ = nx.draw_networkx_labels(G, pos)
return