First working instance of polygraph. Hard-coded everything, but we'll fix that later.
This commit is contained in:
commit
1f659d32ee
41
polygraph.py
Executable file
41
polygraph.py
Executable 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()
|
Loading…
Reference in New Issue
Block a user