在python中使用邻接矩阵和坐标列表绘制连通图
我有一组点(x,y)坐标和邻接矩阵,它给出了连通性的细节。我想用给定的连接性绘制物理坐标。我知道创建连接图和物理坐标的散点图很有用。但我想要的是两者兼而有之 您可以使用在python中使用邻接矩阵和坐标列表绘制连通图,python,matplotlib,coordinates,networkx,adjacency-matrix,Python,Matplotlib,Coordinates,Networkx,Adjacency Matrix,我有一组点(x,y)坐标和邻接矩阵,它给出了连通性的细节。我想用给定的连接性绘制物理坐标。我知道创建连接图和物理坐标的散点图很有用。但我想要的是两者兼而有之 您可以使用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,
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)