-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualizer.py
32 lines (27 loc) · 937 Bytes
/
visualizer.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
import pygraphviz as pgv
import pandas as pd
people = pd.read_csv('people.csv')
relations = pd.read_csv('relations.csv')
a = pgv.AGraph()
for _, row in people.iterrows():
n = row['notes']
p = row['person']
l = '{} [{}]'.format(p, n[n.find('(') + 6:-1] if '(' in n else n[5:])
a.add_node(row['rowid'], label=l)
for _, row in relations.iterrows():
rm = str(int(row['male']))
rd = str(int(row['descendant']))
rf = row['female']
if rf > 0:
# mother listed, indicate with red line
rf = str(int(rf))
a.add_edge(rm, rf, color='red')
# attach descendant to mother's node with black line
a.add_edge(rf, rd, dir='forward', arrowsize=0.7, arrowhead='empty')
else:
# black line from father to descendant
a.add_edge(rm, rd, dir='forward', arrowsize=0.7)
# draw graph to files
a.draw('tree.png', prog='dot')
a.draw('tree.svg', prog='dot')
print('Done!')