You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

graphviz-tale-to-tell.ipynb 3.6KB

graphviz: tale to tell

pip3 install graphviz
apt install graphviz

The graphviz library can be directly used with its commandline commands (like dot, neato, etc.)

In [ ]:
from graphviz import Digraph
In [ ]:
dot = Digraph()
In [ ]:
# Add nodes 1 and 2
dot.node('1')
dot.node('2')

# Add edge between 1 and 2
dot.edges(['12'])
In [ ]:
dot
In [ ]:
text = """I have a tale to tell
Sometimes it gets so hard to hide it well
I was not ready for the fall
Too blind to see the writing on the wall"""
In [ ]:
for word in text.split():
    print (word)
In [ ]:
from itertools import tee
def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)
In [ ]:
for w1, w2 in pairwise(text.split()):
    print (w1, w2)
In [ ]:
for w1, w2 in pairwise(text.split()):
    dot.edge(w1, w2)
In [ ]:
dot
In [ ]:
dot.render("tale")
In [ ]:
dot.render?
In [ ]:
# Example of using the graph as a generator ??
In [ ]:
dot.render("tale", format="png")
In [ ]: