python - How to use igraph to plot two vertices by using non zero-based ID? -
hello new igraph.
i'm trying visualize graph using python module igraph. graph g output of karger min-cut, has 2 vertices.
the problem igraph far in case is, can define vertices id in edges zero-based number (0, 1, ...). cmiiw.
while output of karger min-cut randomly numbered vertices. input of karger min-cut graph 300 vertices ids = 0..299, output graph has 2 vertices random ids numbered 0..299.
e.g. graph g (as input igraph) has edges = [(124, 207), (207, 124)]. if try plot g,
>>> import igraph >>> edges = [(124, 207), (207, 124)] >>> g = igraph.graph(edges=edges, directed=false) >>> layout = g.layout("kk") >>> igraph.plot(g, layout=layout)
then resulting plot has 207 vertices, not 2 vertices expected, should [(0,1), (1,0)], that's 0 based vertices.
how use igraph can plot 2 vertices using non zero-based id?
thank much.
update: have solved problem, suggested @gabor csardi in comment, way,
>>> g = igraph.graph() >>> g.add_vertices(2) >>> g.vs["name"] = ["124", "207"] >>> edges = [("124", "207"), ("207", "124")] >>> g.add_edges(edges) >>> layout = g.layout("kk") >>> igraph.plot(g, layout=layout)
however, if there better solution please answer, thank you.
Comments
Post a Comment