2016-11-11 42 views
1

我试图复制使用Graphviz的这一数字列(在LaTeX中生成的数字):enter image description here定影节点到使用的graphviz

做各种搜索和阅读,我已经成功远远得到这个:

enter image description here

我对获取超级和下标不感兴趣。如果我真的想要的话,我很确定我能确定这一点。我想要做的是确保节点都在3 x 3网格中,并且很好地对齐。正如你所看到的,我的产品没有对齐。我的代码如下。 (这个数字是R中使用制图包制作。

到目前为止,我已经使用[pos='1,1!',pin=true]尝试,并在三个由三格递增位置索引,但它并没有改变结果的。

任何提示?

库(制图)

grViz(
    " 
digraph { 

    graph [overlap = true, fontsize = 10] 
    node [shape=circle] 
    Q11 [pos='1,1',pin=true] 
    Q21 [pos='2,1',pin=true] 
    Y1 [fillcolor=lightgray,style=filled,pos='3,1',pin=true] 

    Q11 -> Q21 
    Q11 -> Y1 
    Q21 -> Y1 

    node [shape = circle] 
    Q12 
    Q22 
    Y2 [fillcolor=lightgray,style=filled] 

    Q12 -> Q22 
    Q12 -> Y2 
    Q22 -> Y2 

    node [shape = circle] 
    Q13 
    Q23 
    Y3 [fillcolor=lightgray,style=filled] 

    Q13 -> Q23 
    Q13 -> Y3 
    Q23 -> Y3 


    {rank = same; Q11; Q12; Q13} 
    Q11 -> Q12 
    Q12 -> Q13 

    {rank = same; Q21; Q22; Q23} 
    Q21 -> Q22 
    Q22 -> Q23 
} 
    ", 
engine = 'neato') 
+0

你可以尝试不同的内部和外部边缘的权重,例如, 'Q11→Q21→Y1 [权重= 2]'和'Q11 - > Y1 [权重= 1]'。结果让你更接近你想去的地方。但最终,手工布置非常容易。 ;) – lukeA

回答

1

则应该通过添加constraint=false属性禁用边缘上的约束很少。

digraph { 
    graph [fontsize=10] 
    node [shape=circle] 
    Q21 
    Q22 
    Q23 
    Q12 
    Q11 
    Q13 

    Q21 -> Q22 [constraint=false] 
    Q22 -> Q23 [constraint=false] 

    Q11 -> Q21 
    Q11 -> Y1 [constraint=false] 
    Q21 -> Y1 

    Q12 -> Q22 
    Q12 -> Y2 [constraint=false] 
    Q22 -> Y2 


    Q13 -> Q23 
    Q13 -> Y3 [constraint=false] 
    Q23 -> Y3 

    {rank = same; Q11; Q12; Q13;} 
    Q11 -> Q12 [constraint=false] 
    Q12 -> Q13 [constraint=false] 

    {rank = same; Q21; Q22; Q23} 
    Y3 [fillcolor=lightgray,style=filled] 
    Y2 [fillcolor=lightgray,style=filled] 
    Y1 [fillcolor=lightgray,style=filled] 
} 

此代码将在下面的图形中生成。

FIxed graph

请了工作演示检查http://graphviz.it/#/LXfbjEui

+0

你,先生,只是让我的一天!谢谢! – Benjamin