graphvizdotneato

Drawing polygons with labeled vertices in graphviz


I'm trying to make basic polygons with graphviz. I have something like this:

graph {
    node [shape=circle]
    A [pos="0,1!"]
    B [pos="0,0!"]
    C [pos="1,0!"]
    D [pos="1,1!"]

    A -- B
    B -- C
    C -- D
    D -- A
}

which displays the following

polygon1

I'd like the circles to disappear and look more like this:

polygon2

I tried switching to shape=point, but the labels disappear. Any suggestions?


Solution

  • When using shape=point, adding a xlabel to each node will display a label outside of the node shape:

    A [pos="0,1!", xlabel="A"]
    

    The documentation states that the label will be placed outside the node shape, but near the node itself. However, those labels are placed last and can sometimes be omitted (forcelabels to the rescue).

    The position or an offset can not be defined.