Search code examples
graphviz

Only show unique edges in graphviz


I have an input file with about ~5000 lines and 1 to 9 nodes per line.

Many edges are not unique and I would like to only show the unique ones.

A more simple example.

graph {
    a -- b
    a -- b
    a -- b
}

Yields

enter image description here

Is there a way to make the above graph yield something like

enter image description here

I know I could change the sample input to

graph {
    a -- b
}

But it would not be easy to do that for my real input.


Solution

  • There actually is a way: Use the strict keyword:

    strict graph G {
        a -- b [label="First"];
        a -- b [label="Second"];
        a -- b [label="Third"];
    }
    

    Result:

    GraphViz output showing combined edges.

    Without strict, all three edges would be shown. Note that it only takes the first edge's attributes, contrary to what the documentation suggests.