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?
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With