【问题标题】:How to print a description string near a node?如何在节点附近打印描述字符串?
【发布时间】:2013-02-12 23:00:54
【问题描述】:

我最近开始使用 DOT 语言来描述二叉树的结构。下面的例子允许绘制一个二叉树,每个节点内都有数字作为标签。

graph tree {
    0 [shape=ellipse]
    1 [shape=ellipse]
    2 [shape=ellipse]
    3 [shape=ellipse]
    4 [shape=ellipse]
    0 -- 1
    0 -- 2
    2 -- 3
    2 -- 4
}

现在,我想在每个节点附近打印一些附加信息,但不在包含节点标签的椭圆内。换句话说,如何在节点附近打印描述字符串?我应该如何修改上面的代码来实现这一点?

【问题讨论】:

    标签: binary-tree graphviz dot


    【解决方案1】:

    这个脚本,加上添加的行,

    graph tree {
        0 [shape=ellipse]
        1 [shape=ellipse]
        2 [shape=ellipse]
        3 [shape=ellipse]
        4 [shape=ellipse]
        0 -- 1
        0 -- 2
        2 -- 3
        2 -- 4
    
    node [shape=none]
    edge [style="invis"]
    rank="same"
    subgraph { 0 -- "desc of 0" }
    subgraph { 1 -- "desc of 1" }
    subgraph { 2 -- "desc of 2" }
    subgraph { 3 -- "desc of 3" }
    subgraph { 4 -- "desc of 4" }
    }
    

    为您的描述生成合理的图像

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-06
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      相关资源
      最近更新 更多