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

View File

@@ -16,7 +16,8 @@
- shell: pip install -r /vagrant/requirements.txt - shell: pip install -r /vagrant/requirements.txt
# Graph drawing # 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 # Setup development env for solar
#- shell: python setup.py develop chdir=/vagrant/solar #- shell: python setup.py develop chdir=/vagrant/solar