'Graphviz flow chart: SyntaxError invalid syntax
I try to create a flow chart whereof I want to change the colors of the nodes. The code of the first flow chart that I created was:
import graphviz
d=graphviz.Digraph()
d.edge('hello','world')
d.edge('new','hello')
d
It works perfectly: simple_flow_chart Although I can not find how to change the colors of the nodes. I tried a few things but it doesn't work. So I tried something else:
digraph {
a -> b;
b -> c;
c -> d;
d -> a;
}
With this code I should be able to change the colors of the nodes if I am correct. But this code gives me a SyntaxError:
File "<ipython-input-46-3bef7a6868e5>", line 1
digraph {
^
SyntaxError: invalid syntax
So an error on the '{', but I don't know why.
Maybe I'm mixing stuff up here. But I'm getting lost. Is there a way to color the nodes with the first code? If not, how do I get the second code working and how do I then color the nodes? Note: Graphviz 2.38 was installed on my Windows computer and the path was added to the environment variables. Every help is appreciated.
Solution 1:[1]
The syntax is different if we want to use it in python. In case we have the .dot file ready, we can direct load it in cmd window to render the graph from the .dot file.
First, make sure the Graphviz is installed in your local environment.
Open cmd window from the directory that contain your .dot file and type the following (rename the input.dot with your actual .dot file name):
dot -Tpng input.dot > output.png
This will generate a .png file with the generated graph in the same directory as the .dot file.
Related discussion: Graphviz: How to go from .dot to a graph?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MK 5012 |