gpt4 book ai didi

vertical-alignment - Graphviz 稀疏矩阵节点对齐

转载 作者:行者123 更新时间:2023-12-04 16:04:28 28 4
gpt4 key购买 nike

我正在尝试用点语言绘制一个稀疏矩阵,实际上节点连接是可以的,但问题是这些节点的垂直对齐,我尝试使用 pos 并放置具有 x 和 y 值的节点,但只是没有t 工作(我认为是因为默认布局)。如果你能帮助我,一个有压力的学生会感谢你。我的点代码如下所示,并生成了图像的链接。

https://github.com/Gualtix/Learn_CPP/blob/master/Matrix.png

谢谢你。

digraph Sparce_Matrix {

node [shape=box]

Mt [label = "Matrix" width = 1.5 style = filled, fillcolor = firebrick1];

//(^< ............ ............ ............ ............ ............ U S U A R I O S
U0 [label = "Estructuras" pos = "5.3,3.5!" width = 1.5 style = filled, fillcolor = bisque1];
U1 [label = "Redes" width = 1.5 style = filled, fillcolor = bisque1];
U2 [label = "Compiladores" width = 1.5 style = filled, fillcolor = bisque1];
U3 [label = "Investigacion" width = 1.5 style = filled, fillcolor = bisque1];
U4 [label = "Lenguajes" width = 1.5 style = filled, fillcolor = bisque1];

//(^< ............ Links
U0 -> U1 { constraint = true };
U1 -> U0 { constraint = true };
U1 -> U2 { constraint = true };
U2 -> U1 { constraint = true };
U2 -> U3 { constraint = true };
U3 -> U2 { constraint = true };
U3 -> U4 { constraint = true };
U4 -> U3 { constraint = true };

//(^< ............ ............ ............ ............ ............ A R C H I V O S
A0 [label = "Josefina" width = 1.5 style = filled, fillcolor = lightskyblue];
A1 [label = "Alejandro" width = 1.5 style = filled, fillcolor = lightskyblue];
A2 [label = "Marco" width = 1.5 style = filled, fillcolor = lightskyblue];
A3 [label = "Julian" width = 1.5 style = filled, fillcolor = lightskyblue];
A4 [label = "Pamela" width = 1.5 style = filled, fillcolor = lightskyblue];

//(^< ............ Links
A0 -> A1;
A1 -> A0;
A1 -> A2;
A2 -> A1;
A2 -> A3;
A3 -> A2;
A3 -> A4;
A4 -> A3;

Mt -> U0;
Mt -> A0 { constraint = true };

{ rank = same; Mt; A0; A1; A2; A3; A4; }

//(^< ............ ............ ............ ............ ............ P E R M I S O S
//(^< ............ ............ L E V E L 0
N0_L0 [label = "Jose-Estr" width = 1.5];
N1_L0 [label = "Marc-Estr" width = 1.5];
N2_L0 [label = "Juli-Estr" width = 1.5];

//(^< ............ ............ L E V E L 2
N0_L2 [label = "Marc-Comp" width = 1.5];
N1_L2 [label = "Juli-Comp" width = 1.5];

//(^< ............ ............ L E V E L 4
N0_L4 [label = "Marc-Leng" width = 1.5];
N1_L4 [label = "Juli-Leng" width = 1.5];
N2_L4 [label = "Pame-Leng" width = 1.5];


//(^< ............ ............ ............ ............ ............ L I N K I N G
//(^< ............ ............ L E V E L 0

U0 -> N0_L0;
A0 -> N0_L0;
N0_L0 -> N1_L0;
N1_L0 -> N0_L0;
A2 -> N1_L0;
N1_L0 -> N2_L0;
N2_L0 -> N1_L0;
A3 -> N2_L0;

{ rank = same; U0; N0_L0;N1_L0;N2_L0; }
//(^< ............ ............ L E V E L 2

U2 -> N0_L2;
N0_L2 ->N1_L0;
N1_L0 ->N0_L2;
N0_L2 -> N1_L2;
N1_L2 -> N0_L2;
N1_L2 ->N2_L0;
N2_L0 ->N1_L2;

{ rank = same; U2; N0_L2;N1_L2; }
//(^< ............ ............ L E V E L 4

U4 -> N0_L4;
N0_L4 ->N0_L2;
N0_L2 ->N0_L4;
N0_L4 -> N1_L4;
N1_L4 -> N0_L4;
N1_L4 ->N1_L2;
N1_L2 ->N1_L4;
N1_L4 -> N2_L4;
N2_L4 -> N1_L4;
A4 -> N2_L4;

{ rank = same; U4; N0_L4;N1_L4;N2_L4; }

}
enter code here

最佳答案

更接近你想要的稀疏矩阵的最重要的工具是 group :

group

If the end points of an edge belong to the same group, i.e., have the same group attribute, parameters are set to avoid crossings and keep the edges straight.


由于您的稀疏矩阵非常稀疏,我还需要一些空节点。我也删除了 [constraint = true]因为无论如何它都是默认值。我所做的更改作为源代码中的注释:
digraph Sparce_Matrix {

node [shape=box]

/* add group 1 for vertical alignment */
Mt[ label = "Matrix", width = 1.5, style = filled, fillcolor = firebrick1, group = 1 ];

/* empty nodes, needed to override graphiz' default node placement */
e0[ shape = point, width = 0 ];
e1[ shape = point, width = 0 ];


//(^< ............ ............ ............ ............ ............ U S U A R I O S
/* groups added for vertical alignment */
U0 [label = "Estructuras" pos = "5.3,3.5!" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U1 [label = "Redes" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U2 [label = "Compiladores" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U3 [label = "Investigacion" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];
U4 [label = "Lenguajes" width = 1.5 style = filled, fillcolor = bisque1, group = 1 ];

//(^< ............ Links
U0 -> U1;
U1 -> U0;
U1 -> U2;
U2 -> U1;
U2 -> U3;
U3 -> U2;
U3 -> U4;
U4 -> U3;

//(^< ............ ............ ............ ............ ............ A R C H I V O S
/* groups 2 to 6 added for vertical alignment */
A0 [label = "Josefina" width = 1.5 style = filled, fillcolor = lightskyblue, group = 2 ];
A1 [label = "Alejandro" width = 1.5 style = filled, fillcolor = lightskyblue, group = 3 ];
A2 [label = "Marco" width = 1.5 style = filled, fillcolor = lightskyblue, group = 4 ];
A3 [label = "Julian" width = 1.5 style = filled, fillcolor = lightskyblue, group = 5 ];
A4 [label = "Pamela" width = 1.5 style = filled, fillcolor = lightskyblue, group = 6 ];

//(^< ............ Links
A0 -> A1;
A1 -> A0;
A1 -> A2;
A2 -> A1;
A2 -> A3;
A3 -> A2;
A3 -> A4;
A4 -> A3;

Mt -> U0;
Mt -> A0;

{ rank = same; Mt; A0; A1; A2; A3; A4; }

//(^< ............ ............ ............ ............ ............ P E R M I S O S
//(^< ............ ............ L E V E L 0
/* groups 2 to 6 added for vertical alignment */
N0_L0 [label = "Jose-Estr" width = 1.5, group = 2 ];
N1_L0 [label = "Marc-Estr" width = 1.5, group = 4 ];
N2_L0 [label = "Juli-Estr" width = 1.5, group = 5 ];

//(^< ............ ............ L E V E L 2
N0_L2 [label = "Marc-Comp" width = 1.5, group = 4 ];
N1_L2 [label = "Juli-Comp" width = 1.5, group = 5 ];

//(^< ............ ............ L E V E L 4
N0_L4 [label = "Marc-Leng" width = 1.5, group = 4 ];
N1_L4 [label = "Juli-Leng" width = 1.5, group = 5 ];
N2_L4 [label = "Pame-Leng" width = 1.5, group = 6 ];


//(^< ............ ............ ............ ............ ............ L I N K I N G
//(^< ............ ............ L E V E L 0

U0 -> N0_L0;
A0 -> N0_L0;
N0_L0 -> N1_L0;
N1_L0 -> N0_L0;
A2 -> N1_L0;
N1_L0 -> N2_L0;
N2_L0 -> N1_L0;
A3 -> N2_L0;

{ rank = same; U0; N0_L0;N1_L0;N2_L0; }
//(^< ............ ............ L E V E L 2

U2 -> N0_L2;
N0_L2 ->N1_L0;
N1_L0 ->N0_L2;
N0_L2 -> N1_L2;
N1_L2 -> N0_L2;
N1_L2 ->N2_L0;
N2_L0 ->N1_L2;

{ rank = same; U2; N0_L2;N1_L2; }
//(^< ............ ............ L E V E L 4

U4 -> N0_L4;
N0_L4 -> N0_L2;
N0_L2 -> N0_L4;
N0_L4 -> N1_L4;
N1_L4 -> N0_L4;
N1_L4 -> N1_L2;
N1_L2 -> N1_L4;
N1_L4 -> N2_L4;
N2_L4 -> N1_L4;

{ rank = same; U4; N0_L4;N1_L4;N2_L4; }

/* we divide the edge from A4 to N2_L4 into 'sub-edges',
thus indirectly making sure that the U nodes stay in their place */
{ rank = same; U2; e0 }
{ rank = same; U3; e1 }
A4 -> e0 -> e1[ dir = none ];
e1 -> N2_L4;
}
产量
enter image description here

关于vertical-alignment - Graphviz 稀疏矩阵节点对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49343366/

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