12

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?

1 Answer 1

11

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

Sign up to request clarification or add additional context in comments.

4 Comments

My problem is now that the g1.render(filename='g1.dot') makes 2 outputs, so i would get a g1.dot and a g1.dot.png. Is it possible to make this g1.dot and g1.png?
you have to notice that g1.view() also produce source and image files.
the library is design that way : if source is named "f.x", image is named "f.x.png". I can't find any way to change it. But you can do it in python (module "os") or in shell.
I just added a one-line solve for my problem: this renames (or replaces) it how i want it to be. move(os.path.join(path, "dotfile.dot.png"), os.path.join(path, "dotfile.png"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.