Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 260
Christoph Avatar asked Jan 22 '18 17:01

Christoph


People also ask

How do I use DOT in graphviz?

How do I use graphviz to convert this into an image? For windows: dl the msi and install; Find gvedit.exe in your programs list; Open . dot file in question; Click running person on toolbar; Go to graph -> settings ; change Output file type to file type of your liking and press ok..


1 Answers

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').

like image 167
Setop Avatar answered Oct 26 '22 22:10

Setop