6
votes

I have the adjacency matrix (i.e. a collection of weights) of a directed graph, and I would like to add labels (corresponding to the values of the weights) on the edges in the final plot. In other words, I would like to obtain something like this. I'm using python igraph, and my code is as follows:

import numpy as np
import igraph as ig


N = 6

adj_matr = np.random.random((N, N))

g = ig.Graph.Weighted_Adjacency(adj_matr.tolist(), mode=ig.ADJ_DIRECTED, attr="weight", loops=True)

ig.plot(g, "My_Graph.svg", vertex_label=map(str, np.arange(N)))

I have figured out how to set labels on the nodes, but I cannot find anything concrete about the edges (adding edge_label=... in the plot command doesn't work). Do you know how to fix the problem? Thanks in advance for your help!

1
What Version are you using? There was a commit that added support for edge labels 4 month ago: github.com/igraph/igraph/commit/…Mailerdaimon
Oh I see, I'm using an old version. For this reason the solutions I found didn't work.user2983638
Since the new version 0.7 is not available yet, how could I fix the problem?user2983638
You could check if the changes made it into the 0.6.7-pre that you can find here: github.com/igraph/igraph/releasesMailerdaimon
Alternatively, try installing a nightly build from igraph.org/nightly . The setup.py installer in the Python version should be smart enough now to download the corresponding C core automatically.Tamás

1 Answers

3
votes

using vertex_label= is equivalent to g.vs=

so to label your edges, use g.es=:

g.es["label"] = ["A", "B", "C"]

or

g.es["name"] = map(str, np.arange(N))