I am trying to force position of nodes. I have x and y coordinates of my nodes and its also directed graph. I can use the rank=same to handle row (y coordinate), but can't figure out how I can handle column (x coordinate).
Asked
Active
Viewed 5.6k times
3 Answers
78
You can use pos attribute (https://www.graphviz.org/doc/info/attrs.html#d:pos), e.g.:
xxx [
label = xxx
pos = "0,0!"
]
yyy [
label = yyy
pos = "10,10!"
]
You will also have to specify neato
or fdp
layout engine, so that dot
command-line would be (for fdp):
dot -Kfdp -n -Tpng -o sample.png sample.dot
-
1I could only get it to work by using `neato -n sample.dot ...` (not fdp) – Arvid Oct 04 '14 at 07:08
-
2Why the exclamation mark ? Can't find anything about it in the manual. And the behavior seems erratic (with version 2.36.0) – kebs Jun 19 '18 at 15:17
-
2so, it doesn't work together with dot layout engine? – Wizard of Kneup Dec 19 '18 at 08:32
-
1any way to only force x or y pos? – Radio Controlled Oct 30 '19 at 09:40
-
3Running `dot` and overriding the layout engine is pretty confusing to people who don't know how it works and doesn't provide any benefit? The documentation specifically mentions "`-K` Specifies which default layout algorithm to use, overriding the default from the command name. For example, running dot -Kneato is equivalent to running neato." – AnnanFay Jan 02 '20 at 00:23
5
Here is an example I found: https://observablehq.com/@magjac/placing-graphviz-nodes-in-fixed-positions
Essentially the position attribute "pos" can be specified for a node. Only works with neato or fdp layout engines, not dot.
The !
indicates that the position is an input and should not be altered.

JP Thomas
- 51
- 1
- 3
0
I couldn't get the -n
flag work with dot -Kfdp
.
I was however able to get it working with neato using the following command:
neato sample.dot -n -Tpng -o sample.png

Jaakko
- 4,674
- 2
- 26
- 20