Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPython Notebook; Plotting transition diagrams

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.

like image 365
tmo Avatar asked Sep 03 '15 12:09

tmo


2 Answers

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.

like image 113
Tristan Reid Avatar answered Sep 28 '22 02:09

Tristan Reid


Right. I found the following packages, installed in the correct order, will produce the graphs I was looking for.

1) Install Graphviz. This is a standalone package, and can be installed with e.g. brew install graphviz.

2) Install PyGraphviz using pip install pygraphviz (requires Graphviz executables)

3) Install PyDot using pip install pydot

If you want to do inline stuff in iPython Notebook, as I do, then check out this

like image 32
tmo Avatar answered Sep 28 '22 03:09

tmo