Just found that the function graph.union does the "sum" I want to do. But,
again, I only can run this function correctly in R, not in Python.
Given the code in R:
library(igraph)
nodes1 = c("a","b","c")
nodes2 = c("c","d","e")
edges1 = matrix( c("a", "b", "b", "c","c","a"), nc = 2, byrow = TRUE)
edges2 = matrix( c("c", "d", "d", "e","e","c"), nc = 2, byrow = TRUE)
g1 = graph(edges1,directed=FALSE)
g2 = graph(edges2,directed=FALSE)
g3 = graph.union(g1,g2);
plot(g3);
Now the equivalent code in Python:
import igraph
nodes1 = ["a","b","c"]
nodes2 = ["c","d","e"]
edges1 = [["a","b"],["b","c"],["c","a"]]
edges2 = [["c","d"],["d","e"],["e","c"]]
g1 = igraph.Graph(directed=False)
g2 = igraph.Graph(directed=False)
g1.add_vertices(nodes1)
g2.add_vertices(nodes2)
g1.add_edges(edges1)
g2.add_edges(edges2)
g3 = igraph.Graph.union(g1,g2)
plot(g3)
As you can see, the behaviour of the plot in Python is still different from
the one in R. Actually, it is worst than the one I had before, because now
I only can see 3 vertices. What am I missing here?
Thanks again for any tip,
Best,
Charles
On 21 September 2015 at 23:16, Charles Novaes de Santana <
[email protected]> wrote:
> Dear all,
>
> I am trying to plot a "sum of graphs" in R and in Python, using Igraph. I
> can do it correctly in R, but I am facing some problems to reproduce it in
> Python. I was wondering if you could help me with this.
>
> Please consider the following toy code in R:
>
> library(igraph)
> nodes1 = c("a","b","c")
> nodes2 = c("c","d","e")
> edges1 = matrix( c("a", "b", "b", "c","c","a"), nc = 2, byrow = TRUE)
> edges2 = matrix( c("c", "d", "d", "e","e","c"), nc = 2, byrow = TRUE)
> g1 = graph(edges1,directed=FALSE)
> g2 = graph(edges2,directed=FALSE)
>
> plot(g1+g2);
>
> you can see that in the plot(g1+g2) the vertex "c" is shared by both
> graphs. So actually I can plot one connected graph with the vertices
> "a","b","c","d","e".
>
> I would like to reproduce it in Python. The best way I think now is the
> following code, but it is failing:
>
> import igraph
> nodes1 = ["a","b","c"]
> nodes2 = ["c","d","e"]
> edges1 = [["a","b"],["b","c"],["c","a"]]
> edges2 = [["c","d"],["d","e"],["e","c"]]
> g1 = igraph.Graph(directed=False)
> g2 = igraph.Graph(directed=False)
> g1.add_vertices(nodes1)
> g2.add_vertices(nodes2)
> g1.add_edges(edges1)
> g2.add_edges(edges2)
>
> igraph.plot(g1+g2);
>
> you can see that the igraph.plot(g1+g2) does not consider that vertex "c"
> is shared by g1 and g2. Do you have any idea why these codes have different
> behaviour? I know I am building the graphs in different ways, but I was not
> able to build the graph in Python in the same way I do it in R.
>
> Sorry if it is a silly question (I used to program in R during some years,
> but I am just a beginner in Python). Thanks for any help or advice!
>
> Best,
>
> Charles
>
> --
> Um axé! :)
>
> --
> Charles Novaes de Santana, PhD
> http://www.imedea.uib-csic.es/~charles
>
--
Um axé! :)
--
Charles Novaes de Santana, PhD
http://www.imedea.uib-csic.es/~charles
_______________________________________________
igraph-help mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/igraph-help