在水平线上指定节点
Specifying nodes on horizontal lines
我已经尝试了几次来绘制一个用直线表示连续状态的图形,S0 -> S1 -> S2。然后在下面的另一条直线上动作。 S0 -> A0 -> S1 -> A1 -> S2 之间存在边。形成并排排列的三角形。
我尝试过使用集群,并且对我要对齐的节点使用 rank=same。我还尝试在 Stack Overflow 上使用 [constraint=false] 和其他答案。
\begin{dot2tex}[fdp]
digraph G {
newrank=true;
node[group="states"]
S0 [texlbl="$S_{t-2}$", shape=none];
S1 [texlbl="$S_{t-1}$", shape=none];
S2 [texlbl="$S_t$", shape=none];
S3 [texlbl="$S_{t+1}$", shape=none];
node[group=""]
A0 [texlbl="$A_{t-2}$", shape=none];
A1 [texlbl="$A_{t-1}$", shape=none];
A2 [texlbl="$A_t$", shape=none];
{ rank=same; S0; S1; S2; S3;
S0 -> S1-> S2 -> S3;
S0 -> A0;
S1 -> A1;
S2 -> A2; }
A0 -> S1;
A1 -> S2;
A2 -> S3;
}
\end{dot2tex}
然而,图表的输出是曲线上状态和动作的混合。
看来您使用的是 fdp 布局引擎。
fdp draws undirected graphs using a ‘‘spring’’model. It relies on a force-directed approach in the spirit ofFruchterman and Reingold
在您的情况下,您需要使用 dot 布局引擎。
我不熟悉您正在使用的程序,但大胆猜测是将 \begin{dot2tex}[fdp]
替换为 \begin{dot2tex}[dot]
您的代码看起来像是 LaTeX 文档的一部分,但它对我不起作用;据我所知,dot2tex
是一个生成 LaTeX 代码的 Python 脚本。但是我在这里超出了我的深度,它似乎对你有用。
我做了什么 - 我已经纠正了你犯的错误,将 rank = same
指令的右大括号 }
放回同一行,并将其从明显的 LaTeX 中取出环境;我还更改了显示 "upwards" 的边缘的箭头方向。然后我把不需要的指令注释掉,到达
digraph G {
# newrank=true;
# node[group="states"]
S0 [texlbl="$S_{t-2}$", shape=none];
S1 [texlbl="$S_{t-1}$", shape=none];
S2 [texlbl="$S_t$", shape=none];
S3 [texlbl="$S_{t+1}$", shape=none];
# node[group=""]
A0 [texlbl="$A_{t-2}$", shape=none];
A1 [texlbl="$A_{t-1}$", shape=none];
A2 [texlbl="$A_t$", shape=none];
{ rank=same; S0; S1; S2; S3; }
S0 -> S1-> S2 -> S3;
S0 -> A0;
S1 -> A1;
S2 -> A2;
edge[ dir = back ];
S1 -> A0;
S2 -> A1;
S3 -> A2;
}
使用
将其转换为 LaTex 文档
dot2tex -ftikz x > x.tex
我明白了
我想这是您想要的,或者至少是您的代码将产生的结果。您的工作流程可能不同,但如果您纠正了主要错误并将右大括号移到它所属的位置,您应该完成了。请注意,dot2tex
默认使用 dot
引擎,这是您应该做的,正如@Dany 正确指出的那样。
如果您想要与 post 中的图片接近的东西,请尝试
digraph G
{
node[ shape =none ]
S [ label = "" ];
S0 [ texlbl="$S_{t-2}$" ];
S1 [ texlbl="$S_{t-1}$" ];
S2 [ texlbl="$S_t$" ];
S3 [ texlbl="$S_{t+1}$" ];
A0 [ texlbl="$A_{t-2}$" ];
A1 [ texlbl="$A_{t-1}$" ];
A2 [ texlbl="$A_t$" ];
{ rank=same; S S0 S1 S2 S3 }
S0 -> S1 -> S2 -> S3
S0 -> A1;
S1 -> A2;
edge[ dir = back ];
S0 -> A0;
S1 -> A1;
S2 -> A2;
edge[ style = invis ];
S -> S1
S -> A0;
}
我已经尝试了几次来绘制一个用直线表示连续状态的图形,S0 -> S1 -> S2。然后在下面的另一条直线上动作。 S0 -> A0 -> S1 -> A1 -> S2 之间存在边。形成并排排列的三角形。
我尝试过使用集群,并且对我要对齐的节点使用 rank=same。我还尝试在 Stack Overflow 上使用 [constraint=false] 和其他答案。
\begin{dot2tex}[fdp]
digraph G {
newrank=true;
node[group="states"]
S0 [texlbl="$S_{t-2}$", shape=none];
S1 [texlbl="$S_{t-1}$", shape=none];
S2 [texlbl="$S_t$", shape=none];
S3 [texlbl="$S_{t+1}$", shape=none];
node[group=""]
A0 [texlbl="$A_{t-2}$", shape=none];
A1 [texlbl="$A_{t-1}$", shape=none];
A2 [texlbl="$A_t$", shape=none];
{ rank=same; S0; S1; S2; S3;
S0 -> S1-> S2 -> S3;
S0 -> A0;
S1 -> A1;
S2 -> A2; }
A0 -> S1;
A1 -> S2;
A2 -> S3;
}
\end{dot2tex}
然而,图表的输出是曲线上状态和动作的混合。
看来您使用的是 fdp 布局引擎。
fdp draws undirected graphs using a ‘‘spring’’model. It relies on a force-directed approach in the spirit ofFruchterman and Reingold
在您的情况下,您需要使用 dot 布局引擎。
我不熟悉您正在使用的程序,但大胆猜测是将 \begin{dot2tex}[fdp]
替换为 \begin{dot2tex}[dot]
您的代码看起来像是 LaTeX 文档的一部分,但它对我不起作用;据我所知,dot2tex
是一个生成 LaTeX 代码的 Python 脚本。但是我在这里超出了我的深度,它似乎对你有用。
我做了什么 - 我已经纠正了你犯的错误,将 rank = same
指令的右大括号 }
放回同一行,并将其从明显的 LaTeX 中取出环境;我还更改了显示 "upwards" 的边缘的箭头方向。然后我把不需要的指令注释掉,到达
digraph G {
# newrank=true;
# node[group="states"]
S0 [texlbl="$S_{t-2}$", shape=none];
S1 [texlbl="$S_{t-1}$", shape=none];
S2 [texlbl="$S_t$", shape=none];
S3 [texlbl="$S_{t+1}$", shape=none];
# node[group=""]
A0 [texlbl="$A_{t-2}$", shape=none];
A1 [texlbl="$A_{t-1}$", shape=none];
A2 [texlbl="$A_t$", shape=none];
{ rank=same; S0; S1; S2; S3; }
S0 -> S1-> S2 -> S3;
S0 -> A0;
S1 -> A1;
S2 -> A2;
edge[ dir = back ];
S1 -> A0;
S2 -> A1;
S3 -> A2;
}
使用
将其转换为 LaTex 文档dot2tex -ftikz x > x.tex
我明白了
我想这是您想要的,或者至少是您的代码将产生的结果。您的工作流程可能不同,但如果您纠正了主要错误并将右大括号移到它所属的位置,您应该完成了。请注意,dot2tex
默认使用 dot
引擎,这是您应该做的,正如@Dany 正确指出的那样。
如果您想要与 post 中的图片接近的东西,请尝试
digraph G
{
node[ shape =none ]
S [ label = "" ];
S0 [ texlbl="$S_{t-2}$" ];
S1 [ texlbl="$S_{t-1}$" ];
S2 [ texlbl="$S_t$" ];
S3 [ texlbl="$S_{t+1}$" ];
A0 [ texlbl="$A_{t-2}$" ];
A1 [ texlbl="$A_{t-1}$" ];
A2 [ texlbl="$A_t$" ];
{ rank=same; S S0 S1 S2 S3 }
S0 -> S1 -> S2 -> S3
S0 -> A1;
S1 -> A2;
edge[ dir = back ];
S0 -> A0;
S1 -> A1;
S2 -> A2;
edge[ style = invis ];
S -> S1
S -> A0;
}