我完全不了解图形学。我有一个213 X 213的距离矩阵,我一直在尝试使用网络可视化距离矩阵,我的想法是远离节点将出现在绘制图形时作为单独的聚类。因此,我正在创建一个以列索引表示节点的图形。我需要跟踪节点以便稍后进行标记。我需要按特定顺序添加边缘,因此需要跟踪节点及其标签。
以下是代码:
import networkx as nx
G = nx.Graph()
G.add_nodes_from(time_pres) ##time_pres is the list of labels that I want specific node to have
for i in range(212):
for j in range(i+1, 212):
color = ['green' if j == i+1 else 'red'][0]
edges.append((i,j, dist[i,j], 'green')) ##This thing requires allocation of distance as per the order in dist matrirx
G.add_edge(i,j, dist = dist[i,j], color = 'green')
目前我的做法是,分配节点的id为数字,而不是按照time_pres标签中的索引顺序。
color
和edges
有什么用处?你能给我们举一个2x2或3x3距离矩阵的小例子,以便我们能够理解你试图实现什么? - Reti43time_pres
变量保存了什么值?只需给我一个3x3的例子中的9。 - Reti43time_pres = [('person1', '1878'), ('person2', '1879')]
。而且dist[0,1]
是 ('person1', '1878') 和 ('person2', '1879')之间的距离。这样理解正确吗? - Reti43