I am trying to make the following digraph face a different direction, from top to bottom, instead of left to right. I have placed rankdir=tb and rank=same for the nodes I would like to be together, but I cannot get the wanted result (which you can see here). Does anyone know why this is happening? The source is directly provided from pygraphviz.
strict digraph "" {
graph [overlap=false,
rankdir=tb,
ranksep=.1,
splines=ortho
];
node [label="\N"];
{
graph [rank=same];
computerVisionPipeline [color=black,
fillcolor=salmon,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="1.computerVisionPipeline",
name="1.computerVisionPipeline",
shape=box,
style=filled];
"computerVisionPipeline.focalDepthsComputation" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="2.focalDepthsComputation",
name="2.focalDepthsComputation",
shape=box,
style=filled];
computerVisionPipeline -> "computerVisionPipeline.focalDepthsComputation";
"computerVisionPipeline.multiStackDepthsSelection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="3.multiStackDepthsSelection",
name="3.multiStackDepthsSelection",
shape=box,
style=filled];
"computerVisionPipeline.focalDepthsComputation" -> "computerVisionPipeline.multiStackDepthsSelection";
"computerVisionPipeline.multiDepthSourcesProcessing" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="4.multiDepthSourcesProcessing",
name="4.multiDepthSourcesProcessing",
shape=box,
style=filled];
"computerVisionPipeline.multiStackDepthsSelection" -> "computerVisionPipeline.multiDepthSourcesProcessing";
"computerVisionPipeline.multiDepth" [color=black,
fillcolor=salmon,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="5.multiDepth",
name="5.multiDepth",
shape=box,
style=filled];
"computerVisionPipeline.multiDepthSourcesProcessing" -> "computerVisionPipeline.multiDepth";
"computerVisionPipeline.multiDepthAggregation" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="8.multiDepthAggregation",
name="8.multiDepthAggregation",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepthAggregation";
"computerVisionPipeline.cellDetection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="9.cellDetection",
name="9.cellDetection",
shape=box,
style=filled];
"computerVisionPipeline.multiDepthAggregation" -> "computerVisionPipeline.cellDetection";
"computerVisionPipeline.cellSelection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="10.cellSelection",
name="10.cellSelection",
shape=box,
style=filled];
"computerVisionPipeline.cellDetection" -> "computerVisionPipeline.cellSelection";
"computerVisionPipeline.featuresExtraction" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="11.featuresExtraction",
name="11.featuresExtraction",
shape=box,
style=filled];
"computerVisionPipeline.cellSelection" -> "computerVisionPipeline.featuresExtraction";
"computerVisionPipeline.featuresSaving" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="12.featuresSaving",
name="12.featuresSaving",
shape=box,
style=filled];
"computerVisionPipeline.featuresExtraction" -> "computerVisionPipeline.featuresSaving";
}
{
graph [rank=same];
"computerVisionPipeline.multiDepth.reconstruction" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="6.reconstruction",
name="6.reconstruction",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth.normalization" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="7.normalization",
name="7.normalization",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth.reconstruction" -> "computerVisionPipeline.multiDepth.normalization";
}
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepth.reconstruction";
}
Can you show what the desired graph should look like, from your description I do not understand well, I can assume that this is it:
The way I achieved it was this:
rankdir=tb,
because dot
engine by default is top-down.graph [rank=same];
but for vertical leveling I used group
attribute, I added two groups g1
and g2
for separate graph to two vertical columns.ranksep
to 2
to add a little more length to the edges.Online editor
Script:
strict digraph "" {
graph [overlap=false,
ranksep=.2,
splines=ortho
];
node [label="\N"];
{
computerVisionPipeline [color=black,
fillcolor=salmon,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="1.computerVisionPipeline",
name="1.computerVisionPipeline",
shape=box,
style=filled];
"computerVisionPipeline.focalDepthsComputation" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="2.focalDepthsComputation",
name="2.focalDepthsComputation",
shape=box,
style=filled];
computerVisionPipeline -> "computerVisionPipeline.focalDepthsComputation";
"computerVisionPipeline.multiStackDepthsSelection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="3.multiStackDepthsSelection",
name="3.multiStackDepthsSelection",
shape=box,
style=filled];
"computerVisionPipeline.focalDepthsComputation" -> "computerVisionPipeline.multiStackDepthsSelection";
"computerVisionPipeline.multiDepthSourcesProcessing" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="4.multiDepthSourcesProcessing",
name="4.multiDepthSourcesProcessing",
shape=box,
style=filled];
"computerVisionPipeline.multiStackDepthsSelection" -> "computerVisionPipeline.multiDepthSourcesProcessing";
"computerVisionPipeline.multiDepth" [color=black, group=g1,
fillcolor=salmon,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="5.multiDepth",
name="5.multiDepth",
shape=box,
style=filled];
"computerVisionPipeline.multiDepthSourcesProcessing" -> "computerVisionPipeline.multiDepth";
"computerVisionPipeline.multiDepthAggregation" [color=black, group=g1,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="8.multiDepthAggregation",
name="8.multiDepthAggregation",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepthAggregation";
"computerVisionPipeline.cellDetection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="9.cellDetection",
name="9.cellDetection",
shape=box,
style=filled];
"computerVisionPipeline.multiDepthAggregation" -> "computerVisionPipeline.cellDetection";
"computerVisionPipeline.cellSelection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="10.cellSelection",
name="10.cellSelection",
shape=box,
style=filled];
"computerVisionPipeline.cellDetection" -> "computerVisionPipeline.cellSelection";
"computerVisionPipeline.featuresExtraction" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="11.featuresExtraction",
name="11.featuresExtraction",
shape=box,
style=filled];
"computerVisionPipeline.cellSelection" -> "computerVisionPipeline.featuresExtraction";
"computerVisionPipeline.featuresSaving" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="12.featuresSaving",
name="12.featuresSaving",
shape=box,
style=filled];
"computerVisionPipeline.featuresExtraction" -> "computerVisionPipeline.featuresSaving";
}
{
"computerVisionPipeline.multiDepth.reconstruction" [color=black, group=g2,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="6.reconstruction",
name="6.reconstruction",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth.normalization" [color=black, group=g2,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="7.normalization",
name="7.normalization",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth.reconstruction" -> "computerVisionPipeline.multiDepth.normalization";
}
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepth.reconstruction";
}
Since the graph is located from top to bottom, you can give nodes the same rank ({rank=same; node1; node2; ...; nodeN}
) for the horizontal arrangement.
Variant for partially horizontal branch, need to specify that the two nodes ("computerVisionPipeline.multiDepth.reconstruction"
,"computerVisionPipeline.multiDepth.normalization"
) have the same rank. To do this, add the following lines:
...
{
rank=same;
"computerVisionPipeline.multiDepth.reconstruction";
"computerVisionPipeline.multiDepth.normalization";
}
}
Image:
Script:
strict digraph "" {
graph [overlap=false,
ranksep=.2,
splines=ortho
];
node [label="\N"];
{
computerVisionPipeline [color=black,
fillcolor=salmon,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="1.computerVisionPipeline",
name="1.computerVisionPipeline",
shape=box,
style=filled];
"computerVisionPipeline.focalDepthsComputation" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="2.focalDepthsComputation",
name="2.focalDepthsComputation",
shape=box,
style=filled];
computerVisionPipeline -> "computerVisionPipeline.focalDepthsComputation";
"computerVisionPipeline.multiStackDepthsSelection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="3.multiStackDepthsSelection",
name="3.multiStackDepthsSelection",
shape=box,
style=filled];
"computerVisionPipeline.focalDepthsComputation" -> "computerVisionPipeline.multiStackDepthsSelection";
"computerVisionPipeline.multiDepthSourcesProcessing" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="4.multiDepthSourcesProcessing",
name="4.multiDepthSourcesProcessing",
shape=box,
style=filled];
"computerVisionPipeline.multiStackDepthsSelection" -> "computerVisionPipeline.multiDepthSourcesProcessing";
"computerVisionPipeline.multiDepth" [color=black, group=g1,
fillcolor=salmon,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="5.multiDepth",
name="5.multiDepth",
shape=box,
style=filled];
"computerVisionPipeline.multiDepthSourcesProcessing" -> "computerVisionPipeline.multiDepth";
"computerVisionPipeline.multiDepthAggregation" [color=black, group=g1,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="8.multiDepthAggregation",
name="8.multiDepthAggregation",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepthAggregation";
"computerVisionPipeline.cellDetection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="9.cellDetection",
name="9.cellDetection",
shape=box,
style=filled];
"computerVisionPipeline.multiDepthAggregation" -> "computerVisionPipeline.cellDetection";
"computerVisionPipeline.cellSelection" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="10.cellSelection",
name="10.cellSelection",
shape=box,
style=filled];
"computerVisionPipeline.cellDetection" -> "computerVisionPipeline.cellSelection";
"computerVisionPipeline.featuresExtraction" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="11.featuresExtraction",
name="11.featuresExtraction",
shape=box,
style=filled];
"computerVisionPipeline.cellSelection" -> "computerVisionPipeline.featuresExtraction";
"computerVisionPipeline.featuresSaving" [color=black,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="12.featuresSaving",
name="12.featuresSaving",
shape=box,
style=filled];
"computerVisionPipeline.featuresExtraction" -> "computerVisionPipeline.featuresSaving";
}
{
"computerVisionPipeline.multiDepth.reconstruction" [color=black, group=g2,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="6.reconstruction",
name="6.reconstruction",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth.normalization" [color=black, group=g2,
fillcolor=lightblue,
fontcolor=black,
fontname="verdana bold",
fontsize=14,
label="7.normalization",
name="7.normalization",
shape=box,
style=filled];
"computerVisionPipeline.multiDepth.reconstruction" -> "computerVisionPipeline.multiDepth.normalization";
}
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepth.reconstruction";
{
rank=same;
"computerVisionPipeline.multiDepth.reconstruction";
"computerVisionPipeline.multiDepth.normalization";
}
}
Variant with full horizontal branch, need to specify that the three nodes ("computerVisionPipeline.multiDepth"
,"computerVisionPipeline.multiDepth.reconstruction"
,"computerVisionPipeline.multiDepth.normalization"
) have the same rank. You can also adjust the edge length with the minlen
attribute.
Image:
and changed part of code from the previous example:
...
"computerVisionPipeline.multiDepth" -> "computerVisionPipeline.multiDepth.reconstruction" [minlen=4];
{
rank=same;
"computerVisionPipeline.multiDepth";
"computerVisionPipeline.multiDepth.reconstruction";
"computerVisionPipeline.multiDepth.normalization";
}
}