#!/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()