簡體   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