Adjust vertices so nodes don't overlap using ig.plot

Hi there,

Thanks in advance for any help!

I am using ig.plot to plot my network but I am unsure how to prevent my nodes from overlapping with one another, all points make up at least 2 nodes per community (see figure)


For reference I am trying to display the network within the confines of a circle.

Below is my code so far
visual_style = {}

import math

Define the desired radius for the circular plot

radius = 1000

Set bbox to create a square plot with sides equal to the diameter of the circular shape

bbox_size = 2 * radius
visual_style[“bbox”] = (bbox_size, bbox_size)
visual_style[“margin”] = 17

Set the layout

my_layout = G.layout_fruchterman_reingold()

Plot the graph

ig.plot(G, out_fig_name, **visual_style)

I’m surprised you say ‘set the layout to circular’ and then use layout_fruchterman_reingold. Fruchterman-Reingold isn’t specifically circular, I thought (please correct me if I’m wrong). One algorithm that’s supposed to be circular is ‘layout_reingold_tilford_circular’. But it seems like that should be used for trees.

From your picture it does look like the end result is nicely circular. Maybe that’s just what happens with a graph that’s connected like yours.

Did you try ‘layout_reingold_tilford_circular’, or maybe other other algorithms, like layout_kamada_kawai?

And what happens if you remove the bounding box?

Thanks for your message - sorry the circular comment was an error on my part (left behind after playing with the different algorithms). I have updated this above. What I have done is create the boundary box as a circle to plot within. I’ve then tried different plotting algorithms but I can’t space the nodes. I tried removing the boundary also but this didn’t fix the issue.

Currently there’s no algorithm in igaph to prevent node overlap. As an alternative, I would suggest looking into Gephi, where this is possible.

:frowning: I thought there would maybe be some algorithm/parameter combination that would push them far enough apart. Or maybe a higher ratio between picture size and node size. But yes, try Gephi :smiley:

Yes, you might get lucky :slight_smile: Gephi has a built-in algorithm to nudge the position of nodes slightly in order to prevent overlaps.

Thanks to both of you. Can I ask in Gephi - how would I achieve a similar effect? I’ve imported my network and would like nodes that form the same communities to be grouped together (with nodes not overlapping).

Is your network weighted? If yes, consider how the layout algorithm you use uses weights. See

https://igraph.org/c/html/latest/igraph-Layout.html#igraph_layout_fruchterman_reingold

https://igraph.org/c/html/latest/igraph-Layout.html#igraph_layout_kamada_kawai

Most layout algorithms don’t support disconnected graphs well and the workaround that’s implemented in igraph won’t do well when you have extreme weights. Make sure your weights are rescaled to be unit magnitude, and that their distribution is not extremely wide. Transform them appropriately before plotting.