0

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.

petezurich
  • 9,280
  • 9
  • 43
  • 57
  • That's not intended to be processed by Python; it's in the Dot language itself, which would be interpreted using the `dot` command. – chepner Nov 20 '18 at 15:14
  • thanks for the quick reply. Do you have a simple example of how to do that? –  Nov 20 '18 at 15:20
  • As with any package, information on how to use it can be found in its [documentation](https://graphviz.readthedocs.io/en/stable/manual.html). Everyone who can help you here got the information from there. You can save a lot of time reading it before asking! – Nearoo Nov 20 '18 at 16:42

1 Answers1

0

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?

MK 5012
  • 29
  • 1
  • 9