Graphviz (DOT) Captions

試著忘記壹切 提交于 2020-02-27 14:13:12

问题


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.


回答1:


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.




回答2:


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.




回答3:


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:



来源:https://stackoverflow.com/questions/4714262/graphviz-dot-captions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!