9

adj is a numpy array in python

from igraph import *
g = Graph.Adjacency(adj.tolist())
plot(g)

The image has not labels of vertices, only nodes and edges. How can I enable plot to show label or vertex sequence? Thanks,

Sean
  • 4,267
  • 10
  • 36
  • 50

1 Answers1

12

You can specify the labels to show as a list in the vertex_label keyword argument to plot():

plot(g, vertex_label=["A", "B", "C"])

If the vertices in your graph happen to have a vertex attribute named label, igraph will use those on the plot by default, so you can also do this:

g.vs["label"] = ["A", "B", "C"]
plot(g)

See the documentation of the Graph.__plot__ function for more details. (plot() is just a thin wrapper that calls the __plot__ method of whichever object you pass to it as the first argument).

Tamás
  • 47,239
  • 12
  • 105
  • 124
  • 1
    Thanks! What is the sequence of the node? i.e., how can I know label 'A' represents node 0? Another off topic question is that where can I find the source code of the layout algorithm? – Sean Oct 10 '13 at 13:33
  • 2
    Nodes and edges in an igraph graph always have numeric IDs starting from zero, and the labels should be specified in increasing order of the numeric IDs. If you constructed the graph using `Graph.Adjacency`, the node with index *i* always corresponds to row/column *i* of the matrix. – Tamás Oct 10 '13 at 13:57
  • 2
    Re the layout: the algorithm that igraph uses when no specific layout algorithm is specified depends on the size of the graph; see https://github.com/igraph/igraph/blob/master/interfaces/python/igraph/__init__.py#L1328 . However, the actual layout algorithms are implemented in C: https://github.com/igraph/igraph/blob/master/src/layout.c – Tamás Oct 10 '13 at 13:59