标签不遵循边缘线

时间:2021-04-29 15:38:22

标签: graphviz

我之前使用 graphviz 来制作更小的图形,这一次结构方程建模类型的图形让我有些头疼。如果使用 spline=line,图表顶部的标签似乎不遵循线条。这在图表的顶部更为突出。

  • 如何让标签正确匹配路径?
digraph plot {

    
    graph [ fontsize = 10, splines=line, nodesep = 0.4];
    
    
    subgraph controls {
        rank = same
        node [shape = box];
            a; b; c; d; e; f;
    }
    
    node [shape = circle]
       G

    node [shape = box ];
        H; I; J; K; L; M; O; P
        
        
    edge [ color = black ]
        X -> G [label = "0.19***"]
        d->G [label = "0.06***"] 
        e->G [label = "-0.15***" color=red]
        a->X [label = "0.3***"] 
        b->X [X = "0.21***"] 
        c->X [label = "0.08***"]
        f->X [label = "-0.08***" color=red] 
        G->H [label = "0.85***"] 
        G->I [label = "0.89***"] 
        G->J [label = "0.76***"] 
        G->K [label = "0.85***"] 
        G->L [label = "0.74***"]
        G->M [label = "0.81***"] 
        G->O [label = "0.8***"]
        G->P [label = "0.76***"]
        a -> G [label = "-0.32***" color=red]
        b->G [label = "0.15***"]
        c->G [label = "0.06***"]
        f->G [label = "-0.12***" color=red]
        d->X [label = "0.06***"] 
        e->X [label = "-0.09***" color=red] 
        G->G [label= 1 ]
    
    subgraph central {
        rank = same
        node [shape = circle]
            G
        node [shape = box];
            X;
    }
    


}

结果:

enter image description here

附言也欢迎其他改进建议。

1 个答案:

答案 0 :(得分:1)

  • Graphviz 不提供遵循边曲线的边标签。有此功能的请求 (https://gitlab.com/graphviz/graphviz/-/issues/2007)。您可能会分享您的兴趣。
  • 您的来源有几个次优
    • G 被声明两次 - 合法但不必要
    • edge b->X 有一个 X 属性而不是标签。没什么大不了的

可能性:

  • 考虑其他布局引擎。 circo 和 twopi 很有趣
  • 增加节点ep
  • 尝试 splines=true(这似乎确实有帮助)
  • 将字体颜色与边缘颜色相匹配
  • 考虑删除 X 和 G 的 rank=same(同样,这似乎确实有帮助)
  • 对于 a-f -> X,尝试使用 taillabel 代替 label

大多数这些更改都是装饰性的,只是为了让我更容易理解。
一个不确定的变化是改变 G 和 X 排名。您的来电。

digraph plot {
    graph [ fontsize = 10, splines=line, nodesep = 0.8];
    splines=true
    
    subgraph controls {
        rank = same
        node [shape = box];
            a; b; c; d; e; f;
    }
    subgraph central {
        //rank = same
        G [shape = circle]
        X [shape = box];
    }
    
    node [shape = box ];
        H; I; J; K; L; M; O; P
        
    edge [ color = black ]
        a->X [taillabel = "0.3***"] 
        b->X [taillabel = "0.21***"] 
        c->X [taillabel = "0.08***"  labelangle=-70]  // tweak
        f->X [taillabel = "-0.08***" color=red] 
        d->X [taillabel = "0.06***"] 
        e->X [taillabel = "-0.09***" color=red] 

        X->G [label = "0.19***"]
        d->G [label = "0.06***"] 
        e->G [label = "-0.15***" color=red]
        a->G [label = "-0.32***" color=red]
        b->G [label = "0.15***"]
        c->G [label = "0.06***"]
        f->G [label = "-0.12***" color=red]
        G->G [label= 1 ]
    
        G->H [label = "0.85***"] 
        G->I [label = "0.89***"] 
        G->J [label = "0.76***"] 
        G->K [label = "0.85***"] 
        G->L [label = "0.74***"]
        G->M [label = "0.81***"] 
        G->O [label = "0.8***"]
        G->P [label = "0.76***"]
}

给予:
enter image description here