Custom DOT statementsΒΆ
To add arbitrary statements to the created DOT source, you can use the
body
attribute of Graph
and Digraph
objects.
It holds the verbatim list
of (str
) lines to be written to the source file
(including their final newline).
Use its append()
or extend()
method:
>>> import graphviz
>>> rt = graphviz.Digraph(comment='The Round Table')
>>> rt.body.append('\t"King Arthur" -> {\n\t\t"Sir Bedevere", "Sir Lancelot"\n\t}\n')
>>> rt.edge('Sir Bedevere', 'Sir Lancelot', constraint='false')
>>> print(rt.source)
// The Round Table
digraph {
"King Arthur" -> {
"Sir Bedevere", "Sir Lancelot"
}
"Sir Bedevere" -> "Sir Lancelot" [constraint=false]
}
Attention
Note that you might need to correctly quote/escape identifiers and strings containing whitespace or other special characters when using this method.