how to use neato with spline and avoid mutual edges overlapping? - graphviz
I have a directed graph with ~20 nodes that I need to have their positions fixed. So, I'm using neato to generate my svg file. The problem is that if I use the straight lines, I have edges overlapping some of the nodes. If a set -Gsplines=true -Gsep=1 the edges avoid the nodes nicely but them the mutual nodes (that is, nodes from a -> b and b -> a) are displayed on top of each other...
Below is a piece of it, for example, where edges 9 -> 12 and 12 -> are completely overlapped.
Does anyone know a way around this? I can go with the straight lines that crosses nodes, but if I can manage to avoid them and have the mutual edges displayed separately, would be ideal. Unfortunately, using plain dot is not an option since the fixed position of the nodes is imperative, since my final goal is to put this on top of a map (which I'm doing "by hand" with inkscape). Solutions in other languages (with examples, if possible), are also appreciated.
digraph {
7 [width=0.388723, shape=circle, style=filled,pos="-5.3642582,-2.953523!", color="#CCFFFF"];
9 [width=1.02852, shape=circle, style=filled,pos="-9.84668,4.0044438!", color="#CCFF00"];
12 [width=0.337023, shape=circle, style=filled,pos="-9.2490238,1.6804541!", color="#CC9933"];
13 [width=0.315507, shape=circle, style=filled,pos="-7.456055,0.035156!", color="#99FFCC"];
17 [width=0.164396, shape=circle, style=filled,pos="-7.2275394,1.8979026!", color="#33FF99"];
9 -> 7 [penwidth=0.644654, color="#CCFF00"];
9 -> 12 [penwidth=2.04003, color="#CCFF00"];
9 -> 13 [penwidth=1.10067, color="#CCFF00"];
9 -> 17 [penwidth=1.79226, color="#CCFF00"];
12 -> 9 [penwidth=0.5, color="#CC9933"];
12 -> 13 [penwidth=0.75431, color="#CC9933"];
12 -> 17 [penwidth=0.828487, color="#CC9933"];
13 -> 7 [penwidth=0.695661, color="#99FFCC"];
17 -> 13 [penwidth=1.78682, color="#33FF99"];
}
This may be a problem with a particular version of graphviz - here's the output I get with 2.28, and it doesn't display the problems you mentioned.
I added simply splines=true; sep=1; in the graph.
I've installed version 2.28 and got the same result as you for this sample of the data.
Unfortunately, for the complete set it breaks down. Without the splines=true it works fine (with straight lines overlapping nodes, as usual). But when I set splines=true, sep=1 it does not generate the svg properly. Runnig it without -Tsvg, I get a memory related error that starts likes this:
*** glibc detected *** neato: free(): invalid next size (normal): 0x0000000001e96c00 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7a6e6)[0x7f256f1856e6]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x6c)[0x7f256f1899cc]
/usr/local/lib/graphviz/libgvplugin_neato_layout.so.6(freeRouter+0x3e)[0x7f256aa0095e]
/usr/local/lib/graphviz/libgvplugin_neato_layout.so.6(+0x19e59)[0x7f256a9eee59]
/usr/local/lib/graphviz/libgvplugin_neato_layout.so.6(splineEdges+0x24d)[0x7f256a9ef3fd]
/usr/local/lib/graphviz/libgvplugin_neato_layout.so.6(neato_layout+0x532)[0x7f256a9ea6e2]
/usr/local/lib/libgvc.so.6(gvLayoutJobs+0x91)[0x7f256f6dae61]
neato[0x400f3c]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7f256f12c30d]
neato[0x400fad]
======= Memory map: ========
The complete graph is this one:
digraph {
graph [size="16.68,8.55",resolution="72",bgcolor=transparent];
1 [width= 0.10000000 shape=circle, style=filled,pos=" 13.39800000, -2.34524000!" color="#FFFFFF"];
2 [width= 0.59517100 shape=circle, style=filled,pos=" 1.70387000, 2.39732000!" color="#FFFFCC"];
3 [width= 1.02015000 shape=circle, style=filled,pos=" 0.71950000, 4.79922000!" color="#FF6600"];
4 [width= 0.42447300 shape=circle, style=filled,pos=" 4.54980430, 2.96880530!" color="#FFFF66"];
5 [width= 0.86597700 shape=circle, style=filled,pos=" 3.76904280, 5.57271100!" color="#FFCCCC"];
6 [width= 1.51677000 shape=circle, style=filled,pos=" 11.65283190, 3.98422860!" color="#FFCC33"];
7 [width= 0.38872300 shape=circle, style=filled,pos=" -5.36425820, -2.95352300!" color="#CCFFFF"];
8 [width= 0.18210900 shape=circle, style=filled,pos=" 7.01074180, 4.85747900!" color="#CCFF99"];
9 [width= 1.02852000 shape=circle, style=filled,pos=" -9.84668000, 4.00444380!" color="#CCFF00"];
10 [width= 0.78439800 shape=circle, style=filled,pos=" 0.15527310, 0.75367640!" color="#CCFFFF"];
11 [width= 0.58314700 shape=circle, style=filled,pos=" 3.67089810, -0.14061090!" color="#CC99FF"];
12 [width= 0.33702300 shape=circle, style=filled,pos=" -9.24902380, 1.68045410!" color="#CC9933"];
13 [width= 0.31550700 shape=circle, style=filled,pos=" -7.45605500, 0.03515600!" color="#99FFCC"];
14 [width= 2.10000000 shape=circle, style=filled,pos=" 7.83691370, 2.19430460!" color="#99FF66"];
15 [width= 1.35638000 shape=circle, style=filled,pos=" 11.44042930, 0.19332270!" color="#CC3399"];
16 [width= 0.37155900 shape=circle, style=filled,pos=" 2.31738250, -2.19430460!" color="#33FFFF"];
17 [width= 0.16439600 shape=circle, style=filled,pos=" -7.22753940, 1.89790260!" color="#33FF99"];
1 -> 6[arrowshape=vee,penwidth= 0.76772236, color="#FFFFFF"];
1 -> 7[arrowshape=vee,penwidth= 0.50000000, color="#FFFFFF"];
1 -> 15[arrowshape=vee,penwidth= 0.57695912, color="#FFFFFF"];
2 -> 3[arrowshape=vee,penwidth= 0.71351528, color="#FFFFCC"];
2 -> 7[arrowshape=vee,penwidth= 0.98261125, color="#FFFFCC"];
2 -> 10[arrowshape=vee,penwidth= 2.98429611, color="#FFFFCC"];
3 -> 2[arrowshape=vee,penwidth= 3.10970125, color="#FF6600"];
3 -> 4[arrowshape=vee,penwidth= 2.19246934, color="#FF6600"];
3 -> 5[arrowshape=vee,penwidth= 3.48380699, color="#FF6600"];
3 -> 8[arrowshape=vee,penwidth= 2.56421761, color="#FF6600"];
3 -> 9[arrowshape=vee,penwidth= 0.86576911, color="#FF6600"];
3 -> 10[arrowshape=vee,penwidth= 3.08433716, color="#FF6600"];
3 -> 16[arrowshape=vee,penwidth= 1.50759938, color="#FF6600"];
3 -> 17[arrowshape=vee,penwidth= 2.42768450, color="#FF6600"];
4 -> 2[arrowshape=vee,penwidth= 3.52409026, color="#FFFF66"];
4 -> 3[arrowshape=vee,penwidth= 1.16680621, color="#FFFF66"];
4 -> 8[arrowshape=vee,penwidth= 2.83247875, color="#FFFF66"];
4 -> 11[arrowshape=vee,penwidth= 3.18186134, color="#FFFF66"];
4 -> 14[arrowshape=vee,penwidth= 3.71014548, color="#FFFF66"];
4 -> 15[arrowshape=vee,penwidth= 1.33899072, color="#FFFF66"];
5 -> 3[arrowshape=vee,penwidth= 0.83007122, color="#FFCCCC"];
5 -> 8[arrowshape=vee,penwidth= 5.11512052, color="#FFCCCC"];
6 -> 1[arrowshape=vee,penwidth= 1.05435052, color="#FFCC33"];
6 -> 8[arrowshape=vee,penwidth= 2.17017566, color="#FFCC33"];
6 -> 15[arrowshape=vee,penwidth= 1.78042048, color="#FFCC33"];
7 -> 13[arrowshape=vee,penwidth= 1.70638297, color="#CCFFFF"];
8 -> 5[arrowshape=vee,penwidth= 3.21975483, color="#CCFF99"];
9 -> 12[arrowshape=vee,penwidth= 2.47722286, color="#CCFF00"];
9 -> 13[arrowshape=vee,penwidth= 1.41201772, color="#CCFF00"];
9 -> 17[arrowshape=vee,penwidth= 2.31502497, color="#CCFF00"];
10 -> 2[arrowshape=vee,penwidth= 1.44435627, color="#CCFFFF"];
10 -> 7[arrowshape=vee,penwidth= 1.03121586, color="#CCFFFF"];
10 -> 16[arrowshape=vee,penwidth= 1.50003087, color="#CCFFFF"];
11 -> 10[arrowshape=vee,penwidth= 1.72840183, color="#CC99FF"];
11 -> 16[arrowshape=vee,penwidth= 2.13382591, color="#CC99FF"];
12 -> 9[arrowshape=vee,penwidth= 0.73349271, color="#CC9933"];
12 -> 13[arrowshape=vee,penwidth= 1.50699757, color="#CC9933"];
13 -> 7[arrowshape=vee,penwidth= 1.39745583, color="#99FFCC"];
13 -> 17[arrowshape=vee,penwidth= 1.13347078, color="#99FFCC"];
14 -> 4[arrowshape=vee,penwidth= 1.30211157, color="#99FF66"];
14 -> 5[arrowshape=vee,penwidth= 1.00132679, color="#99FF66"];
15 -> 1[arrowshape=vee,penwidth= 1.32443039, color="#CC3399"];
15 -> 4[arrowshape=vee,penwidth= 1.63346112, color="#CC3399"];
15 -> 6[arrowshape=vee,penwidth= 2.27386028, color="#CC3399"];
15 -> 14[arrowshape=vee,penwidth= 2.67493819, color="#CC3399"];
16 -> 10[arrowshape=vee,penwidth= 3.33223069, color="#33FFFF"];
16 -> 11[arrowshape=vee,penwidth= 3.32587861, color="#33FFFF"];
17 -> 3[arrowshape=vee,penwidth= 0.88032271, color="#33FF99"];
17 -> 9[arrowshape=vee,penwidth= 0.56000418, color="#33FF99"];
17 -> 13[arrowshape=vee,penwidth= 2.95412645, color="#33FF99"];
}
Related
How to change the arrow size of the graph in Graphviz
When I use the penwidth to change the edge width in Graphviz, the arrow size has been enlarged which has a strange behavior. How could I change the thickness of the edge with a proper arrow size ? strict digraph { rankdir=LR; 0 [image="./state01.png", label="", shape=none]; 1 [image="./state02.png", label="", shape=none]; 2 [image="./state03.png", label="", shape=none]; 3 [image="./state04.png", label="", shape=none]; 4 [image="./state05.png", label="", shape=none]; 5 [image="./state06.png", label="", shape=none]; 6 [image="./state07.png", label="", shape=none]; 7 [image="./state08.png", label="", shape=none]; 8 [image="./state09.png", label="", shape=none]; 9 [image="./state10.png", label="", shape=none]; 10 [image="./state11.png", label="", shape=none]; 11 [image="./state12.png", label="", shape=none]; 0 -> 10 [arrowsize=2, color=red, fontsize=100, label="1.41e-06", penwidth="2.5", style=bold]; 1 -> 5 [arrowsize=2, color=red, fontsize=100, label="2.80e-05", penwidth="3.874038546143974", style=bold]; 2 -> 8 [arrowsize=2, color=red, fontsize=100, label="1.51e-07", penwidth="2.5", style=bold]; 2 -> 11 [arrowsize=2, color=red, fontsize=100, label="1.83e-07", penwidth="2.5", style=bold]; 3 -> 11 [arrowsize=2, color=red, fontsize=100, label="3.00e-06", penwidth="2.5", style=bold]; 4 -> 7 [arrowsize=2, color=red, fontsize=100, label="4.58e-04", penwidth="63.38415155484499", style=bold]; 5 -> 4 [arrowsize=2, color=red, fontsize=100, label="1.61e-04", penwidth="22.296681458902984", style=bold]; 5 -> 7 [arrowsize=2, color=red, fontsize=100, label="1.30e-05", penwidth="2.5", style=bold]; 6 -> 1 [arrowsize=2, color=red, fontsize=100, label="2.38e-05", penwidth="3.292282525626318", style=bold]; 6 -> 5 [arrowsize=2, color=red, fontsize=100, label="7.38e-05", penwidth="10.21068283906899", style=bold]; 6 -> 11 [arrowsize=2, color=red, fontsize=100, label="3.56e-05", penwidth="4.9292236040484125", style=bold]; 8 -> 0 [arrowsize=2, color=red, fontsize=100, label="1.41e-06", penwidth="2.5", style=bold]; 8 -> 10 [arrowsize=2, color=red, fontsize=100, label="4.98e-05", penwidth="6.895987834174217", style=bold]; 9 -> 1 [arrowsize=2, color=red, fontsize=100, label="6.55e-07", penwidth="2.5", style=bold]; 9 -> 2 [arrowsize=2, color=red, fontsize=100, label="3.33e-07", penwidth="2.5", style=bold]; 9 -> 6 [arrowsize=2, color=red, fontsize=100, label="1.33e-04", penwidth="18.42707006915772", style=bold]; 9 -> 8 [arrowsize=2, color=red, fontsize=100, label="4.65e-05", penwidth="6.4296145772978734", style=bold]; 9 -> 10 [arrowsize=2, color=red, fontsize=100, label="4.09e-05", penwidth="5.661779639397044", style=bold]; 9 -> 11 [arrowsize=2, color=red, fontsize=100, label="2.58e-04", penwidth="35.681635435845244", style=bold]; 10 -> 3 [arrowsize=2, color=red, fontsize=100, label="3.00e-06", penwidth="2.5", style=bold]; 10 -> 6 [arrowsize=2, color=red, fontsize=100, label="3.80e-08", penwidth="2.5", style=bold]; 10 -> 11 [arrowsize=2, color=red, fontsize=100, label="8.91e-05", penwidth="12.331844148599716", style=bold]; 11 -> 1 [arrowsize=2, color=red, fontsize=100, label="3.54e-06", penwidth="2.5", style=bold]; 11 -> 4 [arrowsize=2, color=red, fontsize=100, label="2.97e-04", penwidth="41.082766242268384", style=bold]; 11 -> 5 [arrowsize=2, color=red, fontsize=100, label="7.23e-05", penwidth="10.00537346107893", style=bold]; 11 -> 7 [arrowsize=2, color=red, fontsize=100, label="8.43e-06", penwidth="2.5", style=bold]; 11 -> 8 [arrowsize=2, color=red, fontsize=100, label="4.63e-06", penwidth="2.5", style=bold]; }
Write out pre-order, in-order, and post-order traversals given a tree:
Okay, so given this tree I need to write out the pre-order, in-order, and post-order traversals for it. 9 / \ 5 12 / \ / \ 2 7 11 15 / / / \ \ 3 6 10 13 16 \ 17 This is what I've come up with, my teacher didn't do a great job of going over this so I'm not sure if I'm anywhere near correct. pre-order: 9 5 2 3 7 6 12 11 10 13 15 16 17 in-order: 3 2 5 7 6 9 12 11 10 13 15 16 17 post-order: 3 2 6 7 5 10 11 17 16 15 13 12 9 Any help would be greatly appreciated
Pre-order: Do a depth-first traveral and write out the node when you encounter it the first time. So this is correct (9 5 2 3 7 6 12 11 10 13 15 16 17). Post-order: Do a depth-first traversal and write out the node after you have processed all its children. So the correct sequence would be (3 2 6 7 5 10 13 11 17 16 15 12 9). In-order: Do a depth-first traversal and write out the left subtree first, then the node itself and afterwards the right subtree. So the correct sequence would be (3 2 5 6 7 9 10 11 13 12 15 16 17). Here it makes a difference whether a single child is the left or right, for the other methods it doesn't matter.
How to enforce sub graphs to be on the same horizontal line in Graphviz
I'm using graphviz (dot) to generate time expanded graph to use in my master thesis. However, my drawing results the following graph: As you can see, the third line is a little bit shifted to the right.I want all the lines in the same horizontal line. Also i want the x.th node in each line to stay at the same horizontal line of other x.th nodes of lines. Changing the edge weights would not helped me. I could not find anything related to this problem so far. What i want to achieve is something like this: Here is my code: digraph G { 1[label="1"] 2[label="1"] 3[label="1"] 4[label="1"] 5[label="1"] 6[label="1"] 7[label="2"] 8[label="2"] 9[label="2"] 10[label="2"] 11[label="2"] 12[label="2"] 13[label="3"] 14[label="3"] 15[label="3"] 16[label="3"] 17[label="3"] 18[label="3"] 19[label="4"] 20[label="4"] 21[label="4"] 22[label="4"] 23[label="4"] 24[label="4"] rankdir="LR"; node[width=0.15, height=0.15, shape=point]; edge[weight=500, label="1"]; 1 -> 2 -> 3 -> 4 -> 5 -> 6 ; 7 -> 8 -> 9 -> 10 -> 11 -> 12 ; 13 -> 14 -> 15 -> 16 -> 17 -> 18 ; 19 -> 20 -> 21 -> 22 -> 23 -> 24 ; edge[weight=3]; 1 -> 9; 2 -> 9; 3 -> 11; 13 -> 22; 14 -> 22; 15 -> 24; edge[weight=1]; 1 -> 14; 2 -> 15; 3 -> 17; 7 -> 21; 8 -> 23; 9 -> 22; } Any help would be appreciated.
Instead of using weight try using the attribute constraint=false for all edges which go from one "line" to another. Setting constraint to false makes graphviz to not consider those edges when laying out the nodes of the graph. See also this very similar question & answer
As far as I know, the only way is to specify an explicit position for each individual node. See: How to force node position (x and y) in graphviz
Edge direction in digraph depends on presence of label? Likely a bug?
I noticed something very strange with a small graph. It only seems to exist in one certain configuration (that I can find) of said graph. Namely: the direction of one of the edges flips depending on the presence of a label. If the label is present, the edge goes the wrong way, if it is absent, the edge points the right way. Here are the two versions of the graph: As you can see, the arrowhead on the edge titled foobar reverses direction as soon as the label is present. The definition says 4 -> 3, so, as I understand it, the head should be at 3, the tail originating from 4. But the opposite is the case as soon as I add a label. Nothing but the label=foobar attribute was changed in the code. I must apologize for the size of the graph. I would normally try to find a minimal example, but in this case, changing even the slightest thing about the layout of the nodes changes the outcome, and the edge is displayed correctly regardless of the presence of a label. The code is here: digraph G { 2; 3; 6; red; 11; 4; 8; brown; 1; ne2; 12; two; one; yellow; e2; 10; 5; green; four; three; 7; 9; 1 -> 2 [style=bold]; 1 -> 4 [style=bold]; 1 -> 5 [style=bold]; 1 -> 3 [style=bold]; 2 -> ne2 [style=bold]; 2 -> e2 [style=bold]; 4 -> 6 [style=bold]; 4 -> 7 [style=bold]; 6 -> 10 [style=bold]; 6 -> 9 [style=bold]; 6 -> 8 [style=bold]; 7 -> 11 [style=bold]; 7 -> 12 [style=bold]; 5 -> one [style=bold]; 5 -> two [style=bold]; 5 -> three [style=bold]; 5 -> four [style=bold]; 3 -> green [style=bold]; 3 -> red [style=bold]; 3 -> yellow [style=bold]; 3 -> brown [style=bold]; 4 -> 3 [constraint=false ,style=dotted ,label=foobar ,arrowhead=odot]; ne2 -> 4 [constraint=false ,label=head ,style=dotted ,arrowhead=odot]; 7 -> four [constraint=false ,label=baz ,style=dotted ,arrowhead=odot]; 6 -> two [constraint=false ,label=baz ,style=dotted ,arrowhead=odot]; 4 -> 5 [constraint=false ,label=baz ,style=dotted ,arrowhead=odot]; ne2 -> 2 [constraint=false ,label=tail ,style=dotted ,arrowhead=odot]; } My current graphviz version is: dot - graphviz version 2.26.3 (20100126.1600) Did I misunderstand something fundamental about the way these graphs are constructed from dot files? It seems unreasonable to me that the arrow head position should be influenced by the presence of a label.
This is indeed a bug. It was fixed in version 2.28, so upgrading should be sufficient.
Using GraphViz to Diagram an Extensive-Form Game
I'm attempting to diagram an extensive form game in GraphViz. Compiling the code results in a graph that is correct in all ways except one. I want the "War" label to be placed to the left of the edge it labels, such that the edge is closest to "r" and not "W". This is my "game" or graph so far: digraph hierarchy_of_D { graph [rankdir ="UD"] node [color=black,shape=circle] //splines="polyline" I [label="R"] subgraph infoset1 { label="whatever" rank="same" 1 [label="C"] 2 [label="C"] } I -> 1 [label="War"] //fix how this floats right of the line I -> 2 [label="Peace"] 1 -> 2 [style=dashed, dir=none] subgraph info21 { rank="same" 3 [label="(2,2)", rank=sink, shape="plaintext"] 4 [label="(5,1)", rank=sink, shape="plaintext"] 5 [label="(1,5)", rank=sink, shape="plaintext"] 6 [label="(4,4)", rank=sink, shape="plaintext"] } 1 -> 3 [label="War"] 1 -> 4 [label="Peace"] 2 -> 5 [label="War"] 2 -> 6 [label="Peace"] } Any ideas? I've already tried the following, which does not do what I want: 1 -> 3 [label="War/l"] See also this question and that question, neither of which have an answer. C'mon now, this is worth triple points!
Triple points? Well then, the correct answer is that you cannot choose the placement of edge labels. However, you may play with headlabel, labeldirection and labelangle: digraph hierarchy_of_D { node [color=black,shape=circle] I [label="R"] subgraph infoset1 { label="whatever" rank="same" 1 [label="C"] 2 [label="C"] } I -> 1 [headlabel="War", labeldistance=3, labelangle=40] I -> 2 [headlabel="Peace", labeldistance=3, labelangle=-40] 1 -> 2 [style=dashed, dir=none] subgraph info21 { rank="same" 3 [label="(2,2)", rank=sink, shape="plaintext"] 4 [label="(5,1)", rank=sink, shape="plaintext"] 5 [label="(1,5)", rank=sink, shape="plaintext"] 6 [label="(4,4)", rank=sink, shape="plaintext"] } 1 -> 3 [headlabel="War", labeldistance=3, labelangle=40] 1 -> 4 [headlabel="Peace", labeldistance=3, labelangle=-40] 2 -> 5 [headlabel="War", labeldistance=3, labelangle=40] 2 -> 6 [headlabel="Peace", labeldistance=3, labelangle=-40] } Output:
Just for fun, an other workaround I just found: By forcing straight edges between nodes using splines=false and defining edges twice, the edges are drawn as if they were one single edge, but the labels of each edge get to are drawn (most of the time) on different sides of the edge. Therefore by having one edge without a label, and the other one with a label, it is possible to influence the placement of the edge(s) label(s). Your example: digraph hierarchy_of_D { splines=false; node [color=black,shape=circle] I [label="R"] subgraph infoset1 { rank="same" 1 [label="C"] 2 [label="C"] } I -> 1 [label="War "] I -> 1 [label=" "] I -> 2 [label=""] I -> 2 [label="Peace"] 1 -> 2 [style=dashed, dir=none] subgraph info21 { rank="same" 3 [label="(2,2)", rank=sink, shape="plaintext"] 4 [label="(5,1)", rank=sink, shape="plaintext"] 5 [label="(1,5)", rank=sink, shape="plaintext"] 6 [label="(4,4)", rank=sink, shape="plaintext"] } 1 -> 3 [label="War"] 1 -> 3 [label=""] 1 -> 4 [label=""] 1 -> 4 [label="Peace"] 2 -> 5 [label=""] 2 -> 5 [label="War "] 2 -> 6 [label=""] 2 -> 6 [label="Peace"]} And the output: It's not perfect, and your mileage may vary depending on the graph, but I thought it was worth mentioning it.