iPython Notebook; Plotting transition diagrams

tmo picture tmo · Sep 3, 2015 · Viewed 8k times · Source

My question is dead simple.

Is there a package to plot state-transition or markov diagrams that look like any of the following? I am thinking it has to exist, but I simply can't find it!

enter image description here enter image description here

I've really had a search around, also on Stackoverflow, but to no avail.

Answer

Tristan Reid picture Tristan Reid · Nov 8, 2016

If you install graphviz and pygraphviz as mentioned above, you can render dot syntax directly in a ipython/jupyter notebook like this (without the need for networkx):

import pygraphviz as pgv
from IPython.display import Image

def draw(dot):
    return Image(pgv.AGraph(dot).draw(format='png', prog='dot'))

g1 = """digraph top {
   a -> b -> c;
}"""
draw(g1)

This draws:

enter image description here

Complete dot reference here.