-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathother_plots.py
More file actions
70 lines (60 loc) · 2.66 KB
/
Copy pathother_plots.py
File metadata and controls
70 lines (60 loc) · 2.66 KB
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
60
61
62
63
64
65
66
67
68
69
70
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np
from netgraph import Graph
def what_edge(node_lists, edge_list):
pp_edges = []
cc_edges = []
pc_edges = []
for pair in edge_list:
if (pair[0] in node_lists[0]) and (pair[1] in node_lists[0]):
pp_edges.append(pair)
if (pair[0] in node_lists[1]) and (pair[1] in node_lists[1]):
cc_edges.append(pair)
if ((pair[0] in node_lists[1]) and (pair[1] in node_lists[0])) or ((pair[0] in node_lists[0]) and (pair[1] in node_lists[1])):
pc_edges.append(pair)
return pp_edges, cc_edges, pc_edges
def colored_network(G, x):
plt.figure(dpi=400, figsize=(16, 16))
# pos = nx.spring_layout(G)
node_list = np.array([node for node in G.nodes()])
# edge_list = [edge for edge in G.edges()]
pro_node = list(node_list[np.where(x > 0)[0]])
con_node = list(node_list[np.where(x < 0)[0]])
neu_node = list(node_list[np.where(x == 0)[0]])
# nx.draw_networkx_nodes(G, pos, pro_node, node_color='tab:blue', node_size=80, alpha=0.5)
# nx.draw_networkx_nodes(G, pos, con_node, node_color='tab:red', node_size=80, alpha=0.5)
# nx.draw_networkx_nodes(G, pos, neu_node, node_color='tab:black', node_size=80, alpha=0.3)
#
# pp_edges, cc_edges, pc_edges = what_edge([pro_node, con_node, neu_node], edge_list)
# other_edges = list(set(edge_list) - set(pp_edges) - set(cc_edges) - set(pc_edges))
# nx.draw_networkx_edges(G, pos, width=0.05, alpha=0.3)
# nx.draw_networkx_edges(G, pos, edgelist=pp_edges, width=0.1, alpha=0.3, edge_color='tab:blue')
# nx.draw_networkx_edges(G, pos, edgelist=cc_edges, width=0.1, alpha=0.3, edge_color='tab:red')
# nx.draw_networkx_edges(G, pos, edgelist=pc_edges, width=0.1, alpha=1, edge_color='tab:purple')
# nx.draw_networkx_edges(G, pos, edgelist=other_edges, width=0.1, alpha=0.5, edge_color='tab:black')
node_to_community = {}
for node in pro_node:
node_to_community[node] = 0
for node in con_node:
node_to_community[node] = 1
for node in neu_node:
node_to_community[node] = 2
community_map = {
0: 'tab:blue',
1: 'tab:red',
2: 'tab:purple'
}
node_color = {node: community_map[community_id] for node, community_id in node_to_community.items()}
Graph(G,
node_color=node_color,
node_edge_width=0,
node_alpha=0.5,
node_size=2.0,
edge_alpha=0.1,
node_layout='community',
node_layout_kwargs=dict(node_to_community=node_to_community),
edge_layout='bundled',
edge_layout_kwargs=dict(k=2000),)
plt.axis('off')
plt.show()