Last active
December 18, 2015 22:39
-
-
Save geopelia/5855927 to your computer and use it in GitHub Desktop.
Script para generación de grafos usando PyGraphviz, a partir de la información en una BD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import pygraphviz as pgv | |
# conector a bd generico | |
import conexionbd as conex | |
# Los sqls obedecen a un esquema particular de tablas | |
sql1 = "select * from tablas" | |
filas1 = conex.conexionBd(sql1) | |
sql2 = "select * from tablas2" | |
filas2 = conex.conexionBd(sql2) | |
graf = pgv.AGraph() | |
graf.graph_attr['label']='Mi gráfico' | |
for fil in filas1: | |
graf.add_node(fil['IdAccion'], shape='box', color='blue', label=fil['NombreAccion']) | |
graf.add_node(fil['IdEstado'], color='red',label=fil['NombreEstado']) | |
graf.add_edge(fil['IdAccion'], fil['IdEstado'], color="green") | |
for fol in filas2: | |
graf.add_node(fol['IdAccion'], shape='box', color='blue', label=fol['NombreAccion']) | |
graf.add_node(fol['IdEstado'], color='red',label=fol['NombreEstado']) | |
graf.add_edge(fol['IdEstado'],fol['IdAccion']) | |
graf.layout() | |
#graf.draw('file-circo.png', prog='circo') | |
#El estilo dot me gusto mas | |
graf.draw('file-dot.png', prog='dot') | |
#graf.draw('file-neato.png') | |
graf.draw('file.dot') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment