ipysigma icon indicating copy to clipboard operation
ipysigma copied to clipboard

Add a documented case to know how to use extraneous layout

Open Yomguithereal opened this issue 2 years ago • 2 comments

And maybe refactor layout to accept multiple formats.

Yomguithereal avatar Oct 19 '23 14:10 Yomguithereal

Hi @Yomguithereal I'm currently trying to use a pre-computed layout positions in ipysigma, but the nodes are not showing at all. What is the format that the layout mapping should have?

The default pos dicc from networkx has the following format:

{node: (x, y) }, where (x, y) is a tuple.

I tried to convert it to {node: {x, y} } as specified in the documentation, and that is not working either.

pentamorfico avatar Mar 08 '25 05:03 pentamorfico

Ok, reading the code I found the way, in case it can be useful for someone:

The actual format of the layout mapping should be:

layout = {
    "node1": {"x": 0.5, "y": 0.5},
    "node2": {"x": 1.2, "y": 2.3},
    # ...
}

So to convert from a networkx positions dicc to this format you only need to do:

ipysigma_layout = {node: {"x": pos[0], "y": pos[1]} for node, pos in positions.items()}

pentamorfico avatar Mar 08 '25 05:03 pentamorfico