How to add edge labels in Graphviz?

*爱你&永不变心* 提交于 2019-11-27 09:27:17

问题


I am trying to draw a graph using Graphviz, but I need to add labels on the edges. There does not seem to be any way to that in Graphviz. Are there a way out?


回答1:


You use the label property attached to the edge.

digraph G {
 a -> b [ label="a to b" ];
 b -> c [ label="another label"];
}

The above generates a graph that looks something like this.




回答2:


@Andrew Walker has given a great answer!

It's also worth being aware of the labeltooltip attribute. This allows an additional string to be attached to the label of an edge. This is easier for a user than the tooltip attribute, as it can be fiddly to hover directly on an edge. The syntax is as follows:

digraph G {
 a -> b [label="  a to b" labeltooltip="this is a tooltip"];
 b -> c [label="  another label" ];
}

Which gives the following result:




回答3:


You can use label="\E" It will generate bye default label.

For Example:

digraph G {
 a -> b [ label="\E" ];
 b -> c [ label="\E"];
}


来源:https://stackoverflow.com/questions/1806870/how-to-add-edge-labels-in-graphviz

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