gpt4 book ai didi

graphviz - 在graphviz中的节点之间绘制省略号

转载 作者:行者123 更新时间:2023-12-03 23:52:27 28 4
gpt4 key购买 nike

我有兴趣在 graphviz 中的节点之间绘制垂直省略号,如下所示:
enter image description here

我遇到的问题是每当我尝试这样做时,我似乎都无法得到 x3xn垂直排列,如下所示:
enter image description here

这是我尝试过的:

digraph G {
rankdir=LR
splines=line

subgraph cluster_0 {
color=white;
node [style=solid, color=black, shape=circle];
x1 x2 x3 xn [group=g1];
label = "Input Features";
}

subgraph cluster_1 {
color=white;
node [style=solid, color=red2, shape=circle];
a1 [group=g2];
label = "Activation";
}

subgraph cluster_2 {
color=white;
node [style=solid, color=green, shape=circle];
out [group=g3];
label = "Output";
}

x1 -> a1;
x2 -> a1;
x3 -> a1;
a1 -> out;
x3 -> xn [arrowhead="none", color="black:invis:black"];
}

我对graphviz很陌生,所以我什至不确定我是否在这里正确使用子图。我还尝试将子图中的节点添加到组中,但这似乎没有任何作用。

最佳答案

添加

{ rank = same; x1 x2 x3 xn }
x1 -> x2 -> x3[ style = invis ];

到你的第一个子图。这具有以下效果
  • 四个节点都是一层一层,即垂直排列
  • 三个编号的节点保持在一起

  • 这是我的版本:
    digraph G 
    {
    rankdir = LR
    splines = line

    subgraph cluster_0
    {
    color = white;
    node[ style = solid, color = black, shape = circle];
    { rank = same; x1 x2 x3 xn }
    x1 -> x2 -> x3[ style = invis ];
    label = "Input Features";
    }

    subgraph cluster_1
    {
    color = white;
    node[ style = solid, color = red2, shape = circle ];
    a1;
    label = "Activation";
    }

    subgraph cluster_2
    {
    color =white;
    node[ style = solid, color = green, shape = circle ];
    out;
    label = "Output";
    }

    x1 -> a1;
    x2 -> a1;
    x3 -> a1;
    a1 -> out;
    x3 -> xn[ arrowhead = "none", color = "black:invis:black" ];
    }

    这给了你

    enter image description here

    E D I T 回答您评论中的问题;关键是在同一等级内颠倒节点定义和边方向的顺序,这可能是由 rankdir = LR 引起的。布局。毕竟,有一个简单的解决方案!
    digraph G 
    {
    rankdir = LR
    splines = line

    subgraph cluster_0
    {
    color = white;
    label = "Input Features";
    node[ style = solid, color = black, shape = circle ];

    /* define and connect in reverse order */
    { rank = same; xn x3 x2 x1 }
    x3 -> x2 -> x1[ style = invis ];
    xn -> x3[ arrowhead = "none", color = "black:invis:black" ];
    }

    subgraph cluster_1
    {
    color = white;
    node[ style = solid, color = red2, shape = circle ];
    a1;
    label = "Activation";
    }

    subgraph cluster_2
    {
    color =white;
    node[ style = solid, color = green, shape = circle ];
    out;
    label = "Output";
    }

    { x1 x2 x3 } -> a1;
    a1 -> out;
    }

    enter image description here

    关于graphviz - 在graphviz中的节点之间绘制省略号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55508342/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com