从距离矩阵绘制图形或网络? [英] Drawing a graph or a network from a distance matrix?
问题描述
我试图绘制/绘制(matplotlib或其他python库)一个大距离矩阵的2D网络,其中距离将是草绘网络的边缘以及线和节点的节点。
DistMatrix =
['a','b','c','d'],
['a' ,0,0.3,0.4,0.7],
['b',0.3,0,0.9,0.2],
['c',0.4,0.9,0,0.1],
['d',0.7,0.2,0.1,0]]
我正在寻找素描/从这样的(更大的:数千列和线)距离矩阵绘制2D网络:节点'a'通过0.3的边缘深度链接到节点'b',节点'c'和'd'将被边缘深度为0.1。 / p> I'm trying to plot/sketch (matplotlib or other python library) a 2D network of a big distance matrix where distances would be the edges of the sketched network and the line and column its nodes. I'm searching to sketch/plot the 2d network from such (bigger: thousand of columns and lines) distance matrix: node 'a' is linked to node 'b' by an edge depth of 0.3, nodes 'c' and 'd' would be tied by an edge depth of 0.1.
What are the tools/libraries I can used (distance matrix can be converted into numpy matrix) to get the sketch/graphical projection of such network? (pandas, matplotlib, igraph,...?) and some leads to do that quickly (I would not define my self Tkinter function to do that ;-) ) ?
thanks for your incoming answers. The graphviz program yields 这篇关于从距离矩阵绘制图形或网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我可以使用哪些工具/库(距离矩阵可以转换为numpy矩阵)以获得此类网络的草图/图形投影? (熊猫,matplotlib,igraph,...?)和一些导致做到这一点(我不会定义自己的Tkinter函数来做到这一点;-))?
感谢您收到的答案。 graphviz 程序 neato
试图尊重边缘长度。 道格显示一种方式利用 neato
使用
import networkx as nx
import numpy as np
import string
dt = [('len',float)]
A = np.array([(0, 0.3,0.4,0.7),
(0.3,0,0.9,0.2),
(0.4,0.9,0,0.1),
(0.7,0.2,0.1,0)$ b (b))* 10
A = A.view(dt)
G = nx.from_numpy_matrix(A)
G = nx.relabel_nodes(G,dict(zip range(len(G.nodes())),string.ascii_uppercase)))
G = nx.drawing.nx_agraph.to_agraph(G)
G.node_attr。更新(color =red,style =filled)
G.edge_attr.update(color =blue,width =2.0)
G.draw('/ tmp / out.png',format ='png',prog ='neato')
DistMatrix =
[ 'a', 'b', 'c', 'd'],
['a', 0, 0.3, 0.4, 0.7],
['b', 0.3, 0, 0.9, 0.2],
['c', 0.4, 0.9, 0, 0.1],
['d', 0.7, 0.2, 0.1, 0] ]
neato
tries to respect edge lengths. doug shows a way to harness neato
using networkx like this:import networkx as nx
import numpy as np
import string
dt = [('len', float)]
A = np.array([(0, 0.3, 0.4, 0.7),
(0.3, 0, 0.9, 0.2),
(0.4, 0.9, 0, 0.1),
(0.7, 0.2, 0.1, 0)
])*10
A = A.view(dt)
G = nx.from_numpy_matrix(A)
G = nx.relabel_nodes(G, dict(zip(range(len(G.nodes())),string.ascii_uppercase)))
G = nx.drawing.nx_agraph.to_agraph(G)
G.node_attr.update(color="red", style="filled")
G.edge_attr.update(color="blue", width="2.0")
G.draw('/tmp/out.png', format='png', prog='neato')