From 1f659d32ee675d20ad620a59de5be7cd8b5bd0e9 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sat, 8 Sep 2012 01:10:31 -0400 Subject: [PATCH] First working instance of polygraph. Hard-coded everything, but we'll fix that later. --- polygraph.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 polygraph.py diff --git a/polygraph.py b/polygraph.py new file mode 100755 index 0000000..51ec84e --- /dev/null +++ b/polygraph.py @@ -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()