如何使用Networkx程序包显示具有更好分离性的网络? [英] How to display a network with better separation using the Networkx package?

查看:111
本文介绍了如何使用Networkx程序包显示具有更好分离性的网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pytextrank包创建了一个图形对象,如下所示:

I created a graph object using the pytextrank package like so:

import pytextrank
### ........................... 
### Some steps and calculations
### ...........................
graph, ranks = pytextrank.text_rank(path_stage1)

然后我可以使用networkx包制作一个networkx绘图,如下所示:

And I can use the networkx package to make a networkx drawing like so:

import networkx as nx
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(50,50))
nx.draw(graph, with_labels=True) 

plt.show()

但是,正如您所看到的,单词大多集中在中心位置.我希望看到词类之间的更高分隔.我该怎么办?

But as you can see, the words are mostly concentrated around the center. I would like to see higher separation between classes of words. How do I do that?

推荐答案

您正在寻找的是不同的

What you are looking for is a different layout (Networkx's term for node positioning algorithms that are used when drawing graphs). By default, nx.draw() is using spring layout. Changing your layout can be done as follows:

import networkx as nx
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(50,50))
pos = nx.spectral_layout(graph)
nx.draw(graph, pos=pos, with_labels=True) 

plt.show()

您可以尝试一些布局,以找到适合您需求的布局.

You can play with a few layouts to find one that suits your needs.

另一种选择是将图形保存到文件中,并使用 gephi 进行加载,该文件具有很好的GUI可视化和探索您的图表. (还支持几种图形布局算法).

Another option is to save your graph to a file, and load it with gephi, which has a nice GUI for visualizing and exploring your graph. (Also supporting several graph layout algorithms).

这篇关于如何使用Networkx程序包显示具有更好分离性的网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆