我开始igraph
结合使用 python,networkx
因为前者已经实现了network community detection
.
现在我只是从一个加权的、非对称的邻接矩阵和节点标签字典开始。我创建了一个有向图 G, in networkx
,然后将其转换为,并用标记的节点 igraph
graph, g
绘制了结果。igraph
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)
这将创建所需的图表,但我想知道最有效labelling
的方法edges
及其相应的权重。