-
Notifications
You must be signed in to change notification settings - Fork 3
/
draw_visu.py
39 lines (31 loc) · 1.12 KB
/
draw_visu.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
# libraries
import pandas as pd
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from os import walk
import matplotlib
matplotlib.use('Agg')
fig_size = plt.rcParams["figure.figsize"]
fig_size[0]=10
fig_size[1]=8
#plt.rcParams["figure.figsize"] = fig_size
for (dirpath, dirnames, filenames) in walk("./output"):
for file in filenames:
list_from = []
list_to = []
with open ('./output/'+file, 'r+') as f:
lis = [line.split(",") for line in f]
for l in lis:
if len(l) > 1:
list_from.append(file.replace(".csv",""))
list_to.append(l[3].replace('\n', ''))
# Build a dataframe with your connections
df = pd.DataFrame({'from': list_from, 'to': list_to})
# Build your graph
G = nx.from_pandas_edgelist(df, 'from', 'to')
# Graph with Custom nodes:
nx.draw(G, with_labels=True, node_size=1000, node_color="skyblue", node_shape="s", alpha=0.5, linewidths=40, scale = 10)
plt.show()
plt.savefig("./layouts/"+file.replace("csv","png"))
plt.close()