Use graphviz to render graph instead of matplotlib

It looks better
This commit is contained in:
Przemyslaw Kaminski
2015-04-22 10:23:59 +02:00
parent 8b2e7259ca
commit 067922e71e
2 changed files with 17 additions and 10 deletions

24
cli.py
View File

@@ -1,10 +1,11 @@
import click
import json
import matplotlib
matplotlib.use('Agg') # don't show windows
import matplotlib.pyplot as plt
#import matplotlib
#matplotlib.use('Agg') # don't show windows
#import matplotlib.pyplot as plt
import networkx as nx
import os
import subprocess
from x import actions as xa
from x import deployment as xd
@@ -146,12 +147,17 @@ def init_cli_connections():
@click.command()
def graph():
g = xs.connection_graph()
pos = nx.spring_layout(g)
nx.draw_networkx_nodes(g, pos)
nx.draw_networkx_edges(g, pos, arrows=True)
nx.draw_networkx_labels(g, pos)
plt.axis('off')
plt.savefig('graph.png')
nx.write_dot(g, 'graph.dot')
subprocess.call(['dot', '-Tps', 'graph.dot', '-o', 'graph.ps'])
# Matplotlib
#pos = nx.spring_layout(g)
#nx.draw_networkx_nodes(g, pos)
#nx.draw_networkx_edges(g, pos, arrows=True)
#nx.draw_networkx_labels(g, pos)
#plt.axis('off')
#plt.savefig('graph.png')
connections.add_command(graph)

View File

@@ -16,7 +16,8 @@
- shell: pip install -r /vagrant/requirements.txt
# Graph drawing
- apt: name=python-matplotlib state=present
#- apt: name=python-matplotlib state=present
- apt: name=python-graphviz state=present
# Setup development env for solar
#- shell: python setup.py develop chdir=/vagrant/solar