Reputation: 3249
In networkx I am able to input the positions of node to be drawn using the second argument of
nx.draw(G, pos)
For instance I can do something like this:
pos[sourceNode]=(x1,y1)
pos[targetNode]=(x2,y2)
I know that i-graph has an argument layout, but I was not able to discover how to use it!
Can you help me?
Upvotes: 1
Views: 114
Reputation: 37661
You are right; in order to position the nodes yourself, you need to use the layout
argument to plot
. Here are some basic examples showing how to use the automatic layout functions and how to make your own.
First, let's make a simple graph as an example. I am setting the random seed so that my results will be reproducible.
from igraph import *
import random
random.seed(123)
g = Graph.Erdos_Renyi(5, 0.5)
plot(g)
When you just plot like this, you have no control of the layout.
There are a number of built-in functions to use specific algorithms for generating layouts.
LO = g.layout_kamada_kawai()
plot(g, layout=LO)
But if you want to take complete control, you need to build your own layout. A layout is just a sequence of [x,y] pairs that say where to place the nodes. While x works the expected way, the low y coordinates are at the top and the high y-values are at the bottom, so you need to do a little transposition to set up your layout.
LO = [[0.0,1.0], [1.0,0.0], [1.0,1.0], [0.0,0.0], [0.5,-0.5]]
plot(g, layout=LO)
Upvotes: 1