Using dot for graphs

asked 2014-02-01 17:33:54 +0200

anonymous user


updated 2015-01-17 22:28:06 +0200

FrédéricC gravatar image

The graphs should be rendered by 'dot', but layout='graphviz' fails due to an error in the distribution's dot2tex package. So I came up with the following:

def dot(g, otype='png'):
    dottmpfile = 'g'+str(g.graphviz_string().__hash__())+otype
    g.graphviz_to_file_named(dottmpfile, edge_labels=True)
    import subprocess['dot', '-T'+otype, '-o', dottmpfile+'.'+otype, dottmpfile])

Which allows to generate graphs like this:

g = DiGraph({'a' : ['a', 'b'], 'b' : ['b','c'], 'c' : ['d'], 'd' : ['c']}, loops=True)

Is there a better way of calling dot straight?

edit retag flag offensive close merge delete