Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding vertex labels to plot in igraph

Tags:

python

igraph

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,

like image 288
Sean Avatar asked Oct 10 '13 08:10

Sean


1 Answers

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).

like image 167
Tamás Avatar answered Oct 27 '22 18:10

Tamás