'Fixing rendering seed for python graphviz fdp

I create a graph using Graphviz Digraph and everytime I render it, the nodes appear at a different place. Is there a way to fix the "rendering seed" so the graph will be always the same ?

NB: I cannot set manually the node positions since I have tens of nodes in my use case.

Here is a code example generating everytime a different image:

from graphviz import Digraph
dot = Digraph(engine='fdp', format='png')
dot.node("A")
dot.node("B")
dot.node("C")
dot

and two examples of outputs:

first output second output



Solution 1:[1]

According to the documentation, the start attribute is supposed to be used by both the fdp and neato layout engines. It is a startType attribute that is allowed on Graphs. The following should work:

digraph {
    graph [start=your_seed]
    ...
}

which you would set in python by

dot.attr("graph", {
    "start": "your_seed"
})

The graphviz documentation shows an example of using setting the start attribute, but only for neato. I have been unable to find any bug reports regarding this feature failing for fdp, so I have to assume that it is an error in the documentation and fdp does not support the start attribute.

I've included the relevant documentation below (dated June 2021) in the event that this is updated. I've been testing with graphviz version 2.43.0.


Documentation of the start attribute


documentation of the start type


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 Rob Hall