Ask Your Question

pothos's profile - activity

2023-03-06 02:37:29 +0200 received badge  Notable Question (source)
2014-06-29 15:18:41 +0200 received badge  Student (source)
2014-06-29 15:18:28 +0200 received badge  Popular Question (source)
2014-02-01 17:33:54 +0200 asked a question 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?