igraph-help
[Top][All Lists]

## Re: [igraph] Extracting vertex coordinates after plot command, and using

 From: Tamás Nepusz Subject: Re: [igraph] Extracting vertex coordinates after plot command, and using weights in fruchterman_reingold Date: Tue, 15 Mar 2011 14:53:32 +0100

Hi Greg,

I presume you are using Python as you've mentioned it in your email.

> Just wandering if there is a way to extract the coordinates of vertices after
> the plot command?
If I need the coordinates after the plot() command, I usually do it the other
way round: calculate a layout by calling Graph.layout() with the appropriate
parameters and then pass the generated layout to plot(). E.g.:

layout = graph.layout("fruchterman_reingold")
plot(graph, layout=layout)

You can then export the layout to a file if you wish; e.g.:

f = open("layout.txt")
for row in layout:
print >>f, "%f %f" % (row[0], row[1])

> Also, I'm using igraph with python and haven't found a successful way to get
> the 'weights' working with the fruchterman_reingold layout - eg increasing
> force/attraction using edge weights -  a python example/link of this would be
> most appreciated.
The easiest way is probably to use an edge attribute directly. E.g., assuming
that your weights are stored in the "weight" attribute, you can simply do this:

layout = graph.layout("fruchterman_reingold", weights="weight")

You can also pass a list of weights to the weights keyword argument; for
instance, let us take a ring of 10 vertices and set the weight of one of the
edges to 100:

ring = Graph.Ring(10)
layout = ring.layout("fruchterman_reingold", weights=[100] + [1]*9)

You will see that one of the edges on the layout became significantly shorter
than the others.

--
Tamas