-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsld_drawer backup.py
More file actions
87 lines (68 loc) · 1.75 KB
/
Copy pathsld_drawer backup.py
File metadata and controls
87 lines (68 loc) · 1.75 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import matplotlib.pyplot as plt
import networkx as nx
from networkx.algorithms.community import greedy_modularity_communities
def draw_sld(G):
plt.figure(figsize=(15,10))
pos = nx.kamada_kawai_layout(G)
# -------------------------
# AREA DETECTION
# -------------------------
communities = list(greedy_modularity_communities(G))
colors = [
"red",
"blue",
"green",
"orange",
"purple",
"cyan",
"yellow",
"magenta"
]
node_colors = {}
for i, community in enumerate(communities):
color = colors[i % len(colors)]
for node in community:
node_colors[node] = color
# -------------------------
# DRAW EDGES
# -------------------------
for u, v in G.edges():
if node_colors[u] == node_colors[v]:
nx.draw_networkx_edges(
G,
pos,
edgelist=[(u, v)],
edge_color=node_colors[u],
width=2
)
else:
nx.draw_networkx_edges(
G,
pos,
edgelist=[(u, v)],
edge_color="black",
style="dashed",
width=2
)
# -------------------------
# DRAW NODES
# -------------------------
for node in G.nodes():
nx.draw_networkx_nodes(
G,
pos,
nodelist=[node],
node_color=node_colors[node],
node_size=250
)
# -------------------------
# LABELS
# -------------------------
nx.draw_networkx_labels(
G,
pos,
font_size=8
)
plt.title("Area Wise Power Network")
plt.axis("off")
plt.show()