I'm starting to use python igraph
in combination with networkx
as the former has implementations of very recent advances in network community detection
.
For now I'm simply starting with
a weighted, nonsymmetric adjacency matrix and dictionary of node labels. I create a directed graph, G, in networkx
, which I then converted to an igraph
graph, g
, and plotted the result in igraph
with labelled nodes.
import numpy as npy
import networkx as nx
import igraph as ig
# Create adjacency matrix, A, and corresponding directed graph in networkx
A=npy.matrix([[4,7,7,0,0],[3,0,6,0,0],[7,6,0,2,1],[0,0,2,0,4],[0,0,1,4,0]])
G = nx.from_numpy_matrix(A, create_using=nx.DiGraph)
# Dictionary of node labels, simply 'A', 'B', ...'E' for this example
labels_dict={0: 'A', 1: 'B', 2: 'C', 3: 'D', 4: 'E'}
labels=list(labels_dict.values())
# Convert networkx graph to igraph
nx.write_graphml(G,'graph.graphml')
g = ig.read('graph.graphml',format="graphml")
# Plot directed graph using igraph with labeled vertices,
ig.plot(g,vertex_label = labels)
This creates the desired graph, but I'd like to know the most efficient means for labelling
the edges
with their corresponding weights.