繁体   English   中英

在python中用邻接矩阵和坐标列表绘制连接图

[英]Plot a connectivity graph with adjacency matrix and coordinates list in python

我有一组点 (x,y) 坐标以及提供连接细节的邻接矩阵。 我想用给定的连通性绘制物理坐标。 我知道networkx可用于创建连接图和散点图绘制物理坐标。 但我想要的是两者兼而有之。

您可以使用Networkx绘制坐标和连通Networkx

import networkx as nx
import numpy as np

pos = np.random.rand(10, 2) #coordinates, (x, y) for 10 nodes
connect = [tuple(np.random.random_integers(0, 9, size=(2))) for x in range(8)] #random connections

#creation of the graph
graph = nx.Graph()
#adding nodes/connections in the graph
for node in range(len(pos)):
    graph.add_node(node)
graph.add_edges_from(connect)

#plot of the nodes using the (x,y) pairs as coordinates
nx.draw(graph, [(x,y) for x,y in pos], node_size=50)

图形

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM