Graphviz (DOT) Captions
Asked Answered
W

3

26

I need to print a large number of graphs using Graphviz DOT. To distinguish which input each graph corresponds to, I want to also have a caption for each graph. Is there anyway to embed this into the DOT representation of the graphs.

Waffle answered 17/1, 2011 at 14:28 Comment(0)
T
48

You can use label to add a caption to the graph.

Example:

digraph {
    A -> B;
    label="Graph";
    labelloc=top;
    labeljust=left;
}

labelloc and labeljust can be used to determine top/bottom and left/right position of the graph label.

All the details and other attributes that can be used to modify the label (font etc) in the graphviz attribute reference.

Tip: Define the graph label end of your dot file, otherwise subgraphs will inherit those properties.

Thitherto answered 17/1, 2011 at 18:40 Comment(0)
S
11

Graph's can have attributes just like nodes and edges do:

digraph {
    graph [label="The Tale of Two Cities", labelloc=t, fontsize=30];
    node [color=blue];
    rankdir = LR;
    London -> Paris;
    Paris -> London;
}

That dot file produces this graph.

enter image description here

Sheepshank answered 21/7, 2012 at 18:15 Comment(2)
link doesn't work anymore. Could consider attaching them image directly.Americanism
Thank you for this, it is just what I neededRance
R
2

If you are looking for a way to add a caption to a Graph object of graphviz in python. Then the following code can help:

from graphviz import Graph
dot = Graph()
dot.node('1','1')
dot.node('2','2')
dot.edge('1','2', label="link")

dot.attr(label="My caption")
dot.attr(fontsize='25')

dot.render(view=True)

Output:

output

Rocher answered 12/8, 2019 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.