Christoph
Christoph

Reputation: 134

save graphviz source to dot file using python

I am writing a visualisation with graphviz in python. I imported graphviz and pylab. I figured out how to save the graphic representation

import graphviz as gv
import pylab

g1 = gv.Graph(format='png')

g1.node('A')
g1.node('B')
g1.edge('A', 'B')

g1.view()
print(g1.source) 

filename = g1.render(filename='img/g1')

pylab.savefig('filename.png')

How can i save the source to a .dot file?

Upvotes: 10

Views: 34013

Answers (1)

Setop
Setop

Reputation: 2490

When you used g1.render(filename='img/g1'), it dumped the source to img/g1.

Just open it with a text editor.

If you want to name it, used g1.render(filename='g1.dot').

Upvotes: 9

Related Questions