-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGraphVisualization.py
27 lines (21 loc) · 987 Bytes
/
GraphVisualization.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
#!/usr/bin/env python
# coding: utf-8
from graphviz import Digraph
def graph_simple(df, eng = 'dot'):
'''df - dataframe filled with transfer entropies. Eng - graphviz engine for grap plot - Standard: dot'''
edge_style = ""
g = Digraph(engine=eng)
in_graph = []
for k, row in enumerate(df.index):
if any(df.loc[row]):
g.node(str(row),row, shape='oval', fontsize='10', width='0', style='filled', fillcolor='#c9c9c9', color="gray")
in_graph.append(row)
for c, col in enumerate(df.columns):
if any(df[col]):
if col not in in_graph:
g.node(str(col), col, shape='oval', fontsize='10', width='0', style='filled', fillcolor='#c9c9c9', color="gray")
for j, col in enumerate(df.columns):
for i, row in enumerate(df.index):
if(df[col][i]):
g.edge(str(row), str(col), label=str(df.at[row,col]), style= edge_style, color='black')
return g