Vous êtes sur la page 1sur 1

import graphviz as gv

import functools

g1 = gv.Graph(format='svg')

graph = functools.partial(gv.Graph, format='svg')


digraph = functools.partial(gv.Digraph, format='svg')

g3 = graph()

nodes = ['A', 'B', ('C', {})]

edges = [
('A', 'B'),
('B', 'C'),
(('A', 'C'), {}),
]

def add_nodes(graph, nodes):


for n in nodes:
if isinstance(n, tuple):
graph.node(n[0], **n[1])
else:
graph.node(n)
return graph

def add_edges(graph, edges):


for e in edges:
if isinstance(e[0], tuple):
graph.edge(*e[0], **e[1])
else:
graph.edge(*e)
return graph

add_edges(
add_nodes(digraph(), ['A', 'B', 'C']),
[('A', 'B'), ('A', 'C'), ('B', 'C')]
).render('img/g4')