O'Reilly logo

Complex Network Analysis in Python by Dmitry Zinoviev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

iGraph

Here’s how iGraph deals with the Lincoln graph. The edge list contains numerical node identifiers rather than labels, but you can add the labels later as node attributes.

 import​ ​igraph
 edges = [(1, 6), (1, 7), (1, 5), (1, 12), (2, 4), (2, 9), (3, 13), (7, 0),
  (7, 2), (7, 3), (8, 1), (8, 10), (8, 11)]
 labels = [
 "A.L. II"​, ​"A.L."​, ​"Thomas L."​, ​"Jessie Harlan L."​, ​"Mary L. Beckwith"​,
 "Sarah L. Grigsby"​, ​"Edward Baker L."​, ​"Mary L."​, ​"William Wallace L."​,
 "Robert Todd L."​, ​"Robert Todd L. Beckwith"​, ​"Thomas L. Jr."​,
 "Thomas L. III"​, ​"L. Isham"​, ​"George W."​]
 G = igraph.Graph(edges, directed=True)
 G.add_vertex(14)
 G.vs[​"name"​] = labels
 print​(G)
<= IGRAPH DN-- 15 13 --
 + attr: name (v) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required