laying out a large graph with graphviz

PythonGraphviz

Python Problem Overview


My daughters have made a game not unlike tic-tac-toe. Of course as I played it with them I started brute-forcing it in my head...

So at lunchtime I made a quick little Python script to 'solve' the game. And I wanted to see the results graphically, so I generated a dot file of all legal moves:

I've pasted the data here.

When I try and render it using dot, it takes forever and I abort it after a few hours.

If I render it using neato or sfdp etc, it takes a few seconds or less but the layout is impossible to actually read:

sfdp -x -Tpng data.dot > data.png

sfdp

neato -x -Tpng data.dot > data.png

neato

I would be happy for the resulting image to be several megapixels.

How can I lay out and render such a big graph? I am open to non-dot suggestions, like Python libraries that can do the layout too.

(somewhat related link)

Added: my Python script to solve the game and generate the dot file

Python Solutions


Solution 1 - Python

Try this:

sfdp -x -Goverlap=scale -Tpng data.dot > data.png

The -Goverlap preserves the layout but uniformly scales things up until there are no more node overlaps. I was able to get a ~77MB PNG that looks like this when you zoom out. enter image description here

Solution 2 - Python

you could still use the neato but modify the .dot file putting: [splines=true overlap=false]

And your file should look like this:

digraph luffarschack {
    graph [splines=true overlap=false];
    node [shape=none]; 
        ...here your nodes;
        ...here your edges;
}

It should work if you just put in the second line "graph [splines=true overlap=false]" and everything else remains the same.

Solution 3 - Python

In addition to other answers, you may use other tools like Gephi.

> Gephi is the leading visualization and exploration software for all kinds of graphs and networks. Gephi is open-source and free.

Runs on Windows, Mac OS X and Linux.

Solution 4 - Python

I found dot with the default -Kneato too slow on my large graph (svg). I ended up using

dot -Ksfdp -ooutput.svg -Tsvg input.dot

where input.dot was

digraph {
    graph [overlap=false];
    a -> {b c d e f g}
    b -> {c e g x f}
    ...
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWillView Question on Stackoverflow
Solution 1 - PythonjobView Answer on Stackoverflow
Solution 2 - PythonDanielBolocView Answer on Stackoverflow
Solution 3 - PythonChristophe RoussyView Answer on Stackoverflow
Solution 4 - PythonjnnnnnView Answer on Stackoverflow