myahya
myahya

Reputation: 3171

Graphviz (DOT) Captions

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.

Upvotes: 26

Views: 18008

Answers (3)

Ritwik
Ritwik

Reputation: 611

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

Upvotes: 2

Raymond Hettinger
Raymond Hettinger

Reputation: 226181

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

Upvotes: 11

marapet
marapet

Reputation: 56446

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.

Upvotes: 48

Related Questions