Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using dot for graphs

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:

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

Which allows to generate graphs like this:

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

Is there a better way of calling dot straight?

click to hide/show revision 2
retagged

Using dot for graphs

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:

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

Which allows to generate graphs like this:

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

Is there a better way of calling dot straight?