使用Dot Language在Graphviz中压缩有向图

时间:2011-12-22 23:03:12

标签: graphviz dot

我正在尝试实现特定图形(对称置换组的Cayley图)的可视化,就像在这里完成的那样,但使​​用带有Dot的Graphviz 2.28。

cayley http://www.euclideanspace.com/maths/discrete/groups/categorise/finite/cube/cayleyGraph.png

digraph cayley {
    i -> x [color=red];
    i -> y [color=blue];
    x -> xx [color=red];
    x -> xy [color=blue];
    y -> yx [color=red];
    y -> yy [color=blue];
    xx -> xxx [color=red];
    xx -> xxy [color=blue];
    xy -> xyx [color=red];
    xy -> xyy [color=blue];
    yx -> yxx [color=red];
    yx -> xyx [color=blue];
    yy -> yyx [color=red];
    yy -> yyy [color=blue];
    xxx -> i [color=red];
    xxx -> xxxy [color=blue];
    xxy -> xxyx [color=red];
    xxy -> xxyy [color=blue];
    xyx -> xyxx [color=red];
    xyx -> xxyx [color=blue];
    xyy -> yy [color=red];
    xyy -> xyyy [color=blue];
    yxx -> yxxx [color=red];
    yxx -> xx [color=blue];
    yyx -> xxyy [color=red];
    yyx -> xyxx [color=blue];
    yyy -> yyyx [color=red];
    yyy -> i [color=blue];
    xxxy -> xxxyx [color=red];
    xxxy -> yyx [color=blue];
    xxyx -> yyy [color=red];
    xxyx -> xxxyx [color=blue];
    xxyy -> xyy [color=red];
    xxyy -> yxx [color=blue];
    xyxx -> xyxxx [color=red];
    xyxx -> xxx [color=blue];
    xyyy -> xyyyx [color=red];
    xyyy -> x [color=blue];
    yxxx -> y [color=red];
    yxxx -> xyyyx [color=blue];
    yyyx -> xxy [color=red];
    yyyx -> xyxxx [color=blue];
    xxxyx -> xyyy [color=red];
    xxxyx -> yx [color=blue];
    xyxxx -> xy [color=red];
    xyxxx -> yxxx [color=blue];
    xyyyx -> xxxy [color=red];
    xyyyx -> yyyx [color=blue];
}

My Dot生成以下布局:cayley这是一个与前一个相比非常大的图形。是否有任何attribute能够使图表尽可能紧密地压缩到第一个图形?

1 个答案:

答案 0 :(得分:24)

我修改了图形,节点和边缘默认属性等代码,使布局尽可能紧凑。也许有更完美的方法。顺便说一下,节点i位于左侧但不是右侧。

digraph cayley {
    graph[rankdir=LR, center=true, margin=0.2, nodesep=0.1, ranksep=0.3]
    node[shape=circle, fontname="Courier-Bold", fontsize=10, width=0.4, height=0.4, fixedsize=true]
    edge[arrowsize=0.6, arrowhead=vee]
    i -> x [color=red];
    i -> y [color=blue];
    x -> xx [color=red];
    x -> xy [color=blue];
    y -> yx [color=red];
    y -> yy [color=blue];
    xx -> xxx [color=red];
    xx -> xxy [color=blue];
    xy -> xyx [color=red];
    xy -> xyy [color=blue];
    yx -> yxx [color=red];
    yx -> xyx [color=blue];
    yy -> yyx [color=red];
    yy -> yyy [color=blue];
    xxx -> i [color=red];
    xxx -> xxxy [color=blue];
    xxy -> xxyx [color=red];
    xxy -> xxyy [color=blue];
    xyx -> xyxx [color=red];
    xyx -> xxyx [color=blue];
    xyy -> yy [color=red];
    xyy -> xyyy [color=blue];
    yxx -> yxxx [color=red];
    yxx -> xx [color=blue];
    yyx -> xxyy [color=red];
    yyx -> xyxx [color=blue];
    yyy -> yyyx [color=red];
    yyy -> i [color=blue];
    xxxy -> xxxyx [color=red];
    xxxy -> yyx [color=blue];
    xxyx -> yyy [color=red];
    xxyx -> xxxyx [color=blue];
    xxyy -> xyy [color=red];
    xxyy -> yxx [color=blue];
    xyxx -> xyxxx [color=red];
    xyxx -> xxx [color=blue];
    xyyy -> xyyyx [color=red];
    xyyy -> x [color=blue];
    yxxx -> y [color=red];
    yxxx -> xyyyx [color=blue];
    yyyx -> xxy [color=red];
    yyyx -> xyxxx [color=blue];
    xxxyx -> xyyy [color=red];
    xxxyx -> yx [color=blue];
    xyxxx -> xy [color=red];
    xyxxx -> yxxx [color=blue];
    xyyyx -> xxxy [color=red];
    xyyyx -> yyyx [color=blue];
    { rank=same; x; y }
    { rank=same; xx; xy; yx; yy }
    { rank=same; xxx; xxy; xyx; xyy; yxx; yyx; yyy }
    { rank=same; xxxy; xxyx; xxyy; xyxx; xyyy; yxxx; yyyx }
    { rank=same; xxxyx; xyxxx; xyyyx }
}

图像显示如下。

enter image description here