Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the coordinates of nodes in Python Igraph

Tags:

python

igraph

I have to plot a graph using python iGraph, I wanted to know if I could predefine the x-cordinates and y-cordinates of the nodes and if yes how?

like image 773
Nikhil Avatar asked Oct 18 '25 16:10

Nikhil


1 Answers

Just supply a list of coordinates to the layout argument of the plot function. E.g.:

>>> g = Graph.Ring(4, circular=False)
>>> layout = [(0,0), (0,1), (1,1), (1,0)]
>>> plot(g, layout=layout)

Note that igraph will re-scale your layout independently along the X and Y axes to ensure that it fits the bounding box of the plot. If you have a custom layout and you want to ensure that the aspect ratio of the layout is kept, you must also specify the bounding box and the margin explicitly. For instance, if your layout is twice as wide as its height, then you need a plot which is also twice as wide. A bounding box of 800 x 400 pixels would do:

>>> plot(g, layout=layout, margin=0, bbox=(800,400))
like image 140
Tamás Avatar answered Oct 21 '25 04:10

Tamás



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!