First working instance of polygraph. Hard-coded everything, but we'll fix that later.

This commit is contained in:
Anna Rose 2012-09-08 01:10:31 -04:00
commit 1f659d32ee

41
polygraph.py Executable file
View File

@ -0,0 +1,41 @@
#!/usr/bin/python
import pygraphviz as pgv
import json
# These are the categories to use for color-coding the graph.
# These are highly arbitrary categories that suited my purposes, feel free
# to edit them!
# fixme: make these configurable
relationship_colors = { 'yes': 'black',
'no': 'grey',
}
gender_colors = {
'm': 'blue',
'f': 'pink',
'o': 'green',
}
def main():
data = json.load(open('network.dat', 'r'))
graph = pgv.AGraph()
graph.node_attr['style'] = 'filled'
graph.graph_attr['overlap'] = 'prism'
# Add nodes to graph
for user in data:
graph.add_node(user['name'], fillcolor=gender_colors[user['gender']])
# Add edges to graph
for user1 in data:
for (user2, rel) in user1['connections']:
graph.add_edge(user1['name'], user2, color=relationship_colors[rel])
graph.layout()
graph.draw('/tmp/graph.png')
if __name__ == '__main__': main()