简体   繁体   English

python中相似矩阵的Networkx图

[英]Networkx graph out of similarity matrix in python

i am trying the library networkx for the first time trying to plot a graph using a disimilarity matrix i made which has around 500 elements,我第一次尝试使用库 networkx 尝试使用我制作的具有大约 500 个元素的相异矩阵来绘制图形,

array([[0.        , 0.56666667, 0.41666667, ..., 0.8037037 , 0.89814815,
        0.86296296],
       [0.56666667, 0.        , 0.35833333, ..., 0.73703704, 0.91481481,
        0.87037037],
       [0.41666667, 0.35833333, 0.        , ..., 0.8037037 , 0.98148148,
        0.86296296],
       ...,
       [0.8037037 , 0.73703704, 0.8037037 , ..., 0.        , 0.67777778,
        0.85740741],
       [0.89814815, 0.91481481, 0.98148148, ..., 0.67777778, 0.        ,
        0.78518519],
       [0.86296296, 0.87037037, 0.86296296, ..., 0.85740741, 0.78518519,
        0.        ]])

and i want to find a good visual way to show relationships based on distance between them我想找到一种很好的视觉方式来显示基于它们之间距离的关系

i tried我试过

import networkx as nx


G = nx.from_numpy_matrix(dismatrix)
G = nx.relabel_nodes(G, dict(zip(range(len(G.nodes())),string.ascii_uppercase)))  
nx.draw(G, with_labels=True, font_weight='bold')

and the result i found isn't that great .. do you guys have any ways how to improve it or actually show something out of it ?我发现的结果并不是那么好..你们有什么方法可以改进它或实际展示一些东西吗?

graph ploted绘制的图形

You have several options.您有多种选择。 First you could apply a community detection algorithm that uses your edge weights (dissimilarity) to find groups of similar nodes.首先,您可以应用社区检测算法,该算法使用您的边缘权重(相异性)来查找相似节点的组。 These labels can then be used to colour your nodes.然后可以使用这些标签为您的节点着色。

Second, you could simply trim edges using a threshold - such as keep only those edges where similarity >= 0.75.其次,您可以简单地使用阈值修剪边缘 - 例如仅保留相似度 >= 0.75 的那些边缘。

In either case you then need to look at what networkx layout you are using in your plots.无论哪种情况,您都需要查看您在图中使用的 networkx 布局。 These include: spring, spectral, force directed , Circular etc. Once you have your graph It might be easier to create a “nice” visual in graph plotting software such as Gephi.这些包括:弹簧、光谱、力导向、圆形等。一旦你有了你的图形,在诸如 Gephi 之类的图形绘图软件中创建一个“漂亮”的视觉效果可能会更容易。

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

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