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

**URL:** https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610
**Category:** Usage
**Tags:** Python
**Created:** [9 July 2023 04:18 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610 "2023-07-09T04:18:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![MOutram](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@MOutram](https://igraph.discourse.group/u/MOutram)
#### Post date: [9 July 2023 04:18 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/1 "2023-07-09T04:18:35Z")

</div>

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)

 ![Graph](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/f191d2ed4f61db6297a144d63bdb682a34302551.jpeg)  
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)

---

<div class="post-metadata">

### Author: ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)
#### Post date: [9 July 2023 05:55 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/2 "2023-07-09T05:55:43Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![MOutram](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@MOutram](https://igraph.discourse.group/u/MOutram)
#### Post date: [9 July 2023 06:49 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/3 "2023-07-09T06:49:40Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)
#### Post date: [9 July 2023 07:13 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/4 "2023-07-09T07:13:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GroteGnoom](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/grotegnoom/32/428_2.png) [@GroteGnoom](https://igraph.discourse.group/u/GroteGnoom)
#### Post date: [9 July 2023 07:41 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/5 "2023-07-09T07:41:15Z")

</div>

☹ 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 😃

---

<div class="post-metadata">

### Author: ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)
#### Post date: [9 July 2023 08:05 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/6 "2023-07-09T08:05:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![MOutram](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@MOutram](https://igraph.discourse.group/u/MOutram)
#### Post date: [10 July 2023 01:31 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/7 "2023-07-10T01:31:07Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [10 July 2023 13:23 UTC](https://igraph.discourse.group/t/adjust-vertices-so-nodes-dont-overlap-using-ig-plot/1610/8 "2023-07-10T13:23:09Z")

</div>

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_fruchterman_reingold)

[https://igraph.org/c/html/latest/igraph-Layout.html#igraph\_layout\_kamada\_kawai](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.
