Sean
Sean

Reputation: 4525

Adding vertex labels to plot in 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,

Upvotes: 10

Views: 11813

Answers (1)

Tamás
Tamás

Reputation: 48101

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

Upvotes: 13

Related Questions