Gráficos¶
Utilidades¶
Utilidades para crear gráficos:
- LibreOffice Draw
- Draw.io. Bastante completo, se pueden crear gráficos (los genera en xml) y después exportarlo a imagen.
- yEd. Genera gráficos en un formato propio que se pueden migrar a imagen. Permite importar datos desde Excel.
- Uso de yEd para UML
- graphviz
- mermaid. Gráficos estilo Markdown. El problema es que no se ven los gráficos en todos los navegadores.
- PlantUML. Diagramas UML
- Pencil Project
- Google Drawings
- Pencil Project
Graphviz¶
Python¶
Una forma es usarlo desde python, por ejemplo en un cuaderno jupyter y después exportarlo.
Para ello es necesario:
- Instalar grapvhiz
- Añadir su directorio
bin
al PATH - Instalar los componentes de graphviz en python:
conda install graphviz python-graphviz
Ejemplo:¶
from IPython.display import Image
from graphviz import Digraph
# Create Digraph object
dot = Digraph()
# Add nodes 1 and 2
dot.node('1')
dot.node('2')
# Add edge between 1 and 2
dot.edges(['12'])
dot
Más información en https://graphviz.readthedocs.io/en/stable/manual.html
VSCode¶
Otra forma es utilizar una extensión para VSCode, que nos permite tanto ver el gráfico resultante como exportarlo a un formato imagen.
Utilidades con graphviz¶
- erd. Diagramas Entidad/relación
- Python Call Graph. Crea un diagrama de clases a partir de código Python.
- Ladot. Para incluir código LaTeX en gráficos GraphViz.
- dot2tex. Genera código LaTeX a partir de GraphViz.
Hacer diagramas con Python¶
Enlaces
Diagrams¶
Enlaces
Este paquete de Python utiliza Graphviz. Se utiliza para diagramas de arquitectura.
Instalación¶
- Instalar Graphviz
- Instalar diagrams
pip install diagrams
Uso¶
Un diagrama de ejemplo:
from diagrams import Diagram
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDS
from diagrams.aws.network import ELB
from diagrams.aws.integration import SQS
from diagrams.aws.storage import S3
from diagrams.saas.chat import Slack
attributes = {"pad": "1.0", "fontsize": "25"}
with Diagram("message flow", show=True, direction="LR",
outformat="png",
graph_attr=attributes):
elb = ELB("load balancer")
service1 = EC2('Service1')
service2 = EC2('Service2')
service3 = EC2('service3')
db = RDS("primary DB")
elb >> service1 >> db
elb >> service2 >> db
service1 >> SQS('sqs') >> service3 >> S3('s3')
daría este resultado:
Diagramas de flujo con Schemdraw¶
Este código:
import schemdraw
from schemdraw.flow import *
with schemdraw.Drawing() as d:
d+= Start().label("Start")
d+= Arrow().down(d.unit/2)
#Input the string
d+= Data(w = 4).label("Enter a string:\n string")
d+= Arrow().down(d.unit/2)
#Reverse the string
d+= Box(w = 4).label("Reverse the string:\n reverse_string")
d+= Arrow().down(d.unit/2)
#Check if string and reverse_string are same
d+= (decision := Decision(w = 5, h= 5,
S = "True",
E = "False").label("Is \n string\n == \nreverse_string?"))
#If True
d+= Arrow().length(d.unit/2)
d+= (true := Box(w = 5).label("string is a palindrome."))
d+= Arrow().length(d.unit/2)
#End program
d+= (end := Ellipse().label("End"))
#If False. Start the arrow from East of decision box
d+= Arrow().right(d.unit).at(decision.E)
#false is referring to the box where string is not a palindrome.
d+= (false := Box(w = 5).label("string is not\n a palindrome."))
#Add a downward arrow from the South of false box
d+= Arrow().down(d.unit*2.5).at(false.S)
#Extend the arrow to reach the end of the program
d+= Arrow().left(d.unit*2.15)
d.save("output/palindrome flowchart.jpeg", dpi = 300)
daría este resultado:
Última actualización:
April 25, 2022