igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] filter graph based on degree + x, y coordinates has node at


From: Ryanne Turenhout
Subject: Re: [igraph] filter graph based on degree + x, y coordinates has node attributes
Date: Thu, 15 Nov 2012 16:30:42 +0100

Hi,

Sorry, I forgot, I am working in Python.

1. Find all vertices with degree 1 and store their IDs in a list. (Use igraph_degree in C, degree() in R, Graph.degree() in Python)
Got it. This is easy.
2. Find all the edges connecting these vertices. Graph.es.select(_within=vertices) in Python.
Aha. I'll try this. Did not know about "_within"
3. Delete the selected edges. (the delete() method of whatever was returned by Graph.es.select(...) in Python).
Ok great. I'll let you know if I get it to work.

layout = g.layout("fr")
g.vs["x"], g.vs["y"] = zip(*layout)
Thanks! That helps me out a lot!
 
Best,
Ryanne

On Thursday, 15 November 2012 at 16:24, Tamás Nepusz wrote:

Hi,

You did not mention whether you are working with igraph in C, R or Python so I can give you only some generic ideas:

I want to filter a graph that I made. If a vertex has a degree 1 and is connected to another vertex who has also got degree 1 -> delete both vertices (and also the corresponding edge).

But if a vertex has a degree 1 and is connected to a vertex with degree > 1 do not delete the vertex.
1. Find all vertices with degree 1 and store their IDs in a list. (Use igraph_degree in C, degree() in R, Graph.degree() in Python)

2. Find all the edges connecting these vertices. (Use igraph_es_fromto in C, E(g)[vertices %--% vertices] in R, or Graph.es.select(_within=vertices) in Python.

3. Delete the selected edges. (Use igraph_delete_edges in C, delete.edges in R, or the delete() method of whatever was returned by Graph.es.select(...) in Python).

Second,
I want to layout the graph but I want to add the coordinates as attributes to the nodes instead of plotting it as an image file. How to go about this? I cannot find any examples.
The layout algorithms in igraph (e.g., layout.fruchterman.reingold in R) simply return a matrix. Just assign these to the vertices as attributes.

In R:

layout <- layout.fruchterman.reingold(g)
V(g)$x <- layout[,1]
V(g)$y <- layout[,2]

In Python:

layout = g.layout("fr")
g.vs["x"], g.vs["y"] = zip(*layout)

--
T.


_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help


reply via email to

[Prev in Thread] Current Thread [Next in Thread]