gpt4 book ai didi

graph - 在 graphviz 中先水平组织盒子,然后垂直组织盒子

转载 作者:行者123 更新时间:2023-12-03 00:13:34 25 4
gpt4 key购买 nike

有没有办法让盒子在某些情况下水平显示,而在其他情况下垂直显示? (参见related question)。

这是我得到的代码和输出:

代码:

/**
** Diagram representing the Simulator Engine
**/
digraph G {
graph [
rankdir = "TB"
];

/**
** The simulator engine rectangle
**/
subgraph cluster_simulator_engine {
style=filled;
color=lightgrey;
node [style=filled,color=white];
label = "Simulator Engine";

/**
** The first topology
**/
subgraph cluster_T1 {
color=white;
node [style=filled];

/**
** The n^th neuron
**/
subgraph cluster_T1_N3 {
color=lightgrey;
node [style=filled];
label = "Neuron n";

/**
** The n^th synapse
**/
"T1_N3_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T1_N3_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T1_N3_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

/*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
}

/**
** The second neuron
**/
subgraph cluster_T1_N2 {
color=lightgrey;
node [style=filled];
label = "Neuron 2";

/**
** The n^th synapse
**/
"T1_N2_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T1_N2_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T1_N2_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

/*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
}


/**
** The third neuron
**/
subgraph cluster_T1_N1 {
color=lightgrey;
node [style=filled];
label = "Neuron 1";

/**
** The n^th synapse
**/
"T1_N1_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T1_N1_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T1_N1_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

/*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
}


label = "Topology 1";
}

/**
** The second topology
**/
subgraph cluster_T2 {
color=white;
node [style=filled];

/**
** The n^th neuron
**/
subgraph cluster_T2_N3 {
color=lightgrey;
node [style=filled];
label = "Neuron n";

/**
** The n^th synapse
**/
"T2_N3_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T2_N3_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T2_N3_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

/*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
}

/**
** The second neuron
**/
subgraph cluster_T2_N2 {
color=lightgrey;
node [style=filled];
label = "Neuron 2";

/**
** The n^th synapse
**/
"T2_N2_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T2_N2_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T2_N2_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

/*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
}


/**
** The third neuron
**/
subgraph cluster_T2_N1 {
color=lightgrey;
node [style=filled];
label = "Neuron 1";

/**
** The n^th synapse
**/
"T2_N1_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T2_N1_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T2_N1_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

/*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/
}


label = "Topology 2";
}

}

}

输出:

First Diagram

显然这太长了。我想要的是将每个突触移动到自己的行中(我认为这在 Graphviz 行话中称为“等级”)。显然,没有办法做到这一点,但有一个 trick 。因此,我采用上面相同的代码并像这样引入不可见边缘

代码:

/**
** Diagram representing the Simulator Engine
**/
digraph G {
graph [
rankdir = "TB"
];

/**
** The simulator engine rectangle
**/
subgraph cluster_simulator_engine {
style=filled;
color=lightgrey;
node [style=filled,color=white];
label = "Simulator Engine";

/**
** The first topology
**/
subgraph cluster_T1 {
color=white;
node [style=filled];

/**
** The n^th neuron
**/
subgraph cluster_T1_N3 {
color=lightgrey;
node [style=filled];
label = "Neuron n";

/**
** The n^th synapse
**/
"T1_N3_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T1_N3_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T1_N3_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

"T1_N3_S1" -> "T1_N3_S2" [style=invis];
"T1_N3_S2" -> "T1_N3_S3" [style=invis];
}

/**
** The second neuron
**/
subgraph cluster_T1_N2 {
color=lightgrey;
node [style=filled];
label = "Neuron 2";

/**
** The n^th synapse
**/
"T1_N2_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T1_N2_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T1_N2_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

"T1_N2_S2" -> "T1_N2_S3" [style=invis];
"T1_N2_S1" -> "T1_N2_S2" [style=invis];
}


/**
** The third neuron
**/
subgraph cluster_T1_N1 {
color=lightgrey;
node [style=filled];
label = "Neuron 1";

/**
** The n^th synapse
**/
"T1_N1_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T1_N1_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T1_N1_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

"T1_N1_S1" -> "T1_N1_S2" [style=invis];
"T1_N1_S2" -> "T1_N1_S3" [style=invis];
}


label = "Topology 1";
}

/**
** The second topology
**/
subgraph cluster_T2 {
color=white;
node [style=filled];

/**
** The n^th neuron
**/
subgraph cluster_T2_N3 {
color=lightgrey;
node [style=filled];
label = "Neuron n";

/**
** The n^th synapse
**/
"T2_N3_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T2_N3_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T2_N3_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

"T2_N3_S1" -> "T2_N3_S2" [style=invis];
"T2_N3_S2" -> "T2_N3_S3" [style=invis];
}

/**
** The second neuron
**/
subgraph cluster_T2_N2 {
color=lightgrey;
node [style=filled];
label = "Neuron 2";

/**
** The n^th synapse
**/
"T2_N2_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T2_N2_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T2_N2_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

"T2_N2_S1" -> "T2_N2_S2" [style=invis];
"T2_N2_S2" -> "T2_N2_S3" [style=invis];
}


/**
** The third neuron
**/
subgraph cluster_T2_N1 {
color=lightgrey;
node [style=filled];
label = "Neuron 1";

/**
** The n^th synapse
**/
"T2_N1_S3" [
style=filled
shape=box
color=white
label="Synapse n"
];

/**
** The second synapse
**/
"T2_N1_S2" [
style=filled
shape=box
color=white
label="Synapse 2"
];

/**
** The first synapse
**/
"T2_N1_S1" [
style=filled
shape=box
color=white
label="Synapse 1"
];

"T2_N1_S1" -> "T2_N1_S2" [style=invis];
"T2_N1_S2" -> "T2_N1_S3" [style=invis];
}


label = "Topology 2";
}

}

}

现在的输出看起来更有吸引力。

输出: Second smaller diagram

但是现在突触盒之间存在巨大的间隙。设置 nodesep=0.1len=0.1 无效。谁能告诉我如何解决这个问题,或者如何重新设计这个问题。

注意:如果有人好奇为什么我从 1 到 2 到 n,那是因为我打算在那里放一个省略号,但我不知道如何做到这一点......当我到达时穿过那座桥它。

最佳答案

这是 ranksep您正在寻找 - 将此行添加到图表的属性中:

ranksep = 0.1

In dot, this gives the desired rank separation, in inches. This is theminimum vertical distance between the bottom of the nodes in one rankand the tops of nodes in the next.

关于graph - 在 graphviz 中先水平组织盒子,然后垂直组织盒子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9092893/

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