igraph-help
[Top][All Lists]
Advanced

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

[igraph] Different plotting of graphs in R and in Python


From: Charles Novaes de Santana
Subject: [igraph] Different plotting of graphs in R and in Python
Date: Mon, 21 Sep 2015 23:16:28 +0200

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

reply via email to

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