python(和networkx)的forceatlas2算法
ForceAtlas2的Python项目详细描述
这是gephi的forceatlas2布局算法到python 2和 python 3(带有networkx的包装器)。
安装
唯一严格的依赖是numpy。强烈推荐赛松 根据图表的不同,它将加速10-100倍。 两者都可以安装:
pip install numpy pip install cython
要使用networkx包装函数,显然需要networkx。
然后要安装此软件包,它是典型的:
python setup.py install
示例用法
定义了两个核心功能:
- forceatlas2.forceatlas2接受邻接矩阵并可选 初始位置和其他可选参数。它用这个来 计算布局。
- forceatlas2.forceatlas2网络布局 返回与NetworkX兼容的布局。
在NetworkX中使用:
import matplotlib.pyplot as plt import networkx import random import forceatlas2 G = networkx.karate_club_graph() pos = { i : (random.random(), random.random()) for i in G.nodes()} # Optionally specify positions as a dictionary l = forceatlas2.forceatlas2_networkx_layout(G, pos, niter=1000) # Optionally specify iteration count networkx.draw_networkx(G, l) plt.show()
注意,我的编码风格是非pythonic的,因为我不使用函数 文档字符串。你得看看函数定义 在forceatlas2.py中查看所有潜在的 论据。
版权所有
这些文件版权所有2016 Max Shinn<;mws41@cam.ac.uk>;和 在GNU GPLV3下可用。它们主要基于Java GEPHI中包含的文件,修订版Git修订版1FBA8C1。(不是这样的 清除?)本模块中包含的文件的版权信息是 根据是:
Copyright 2008-2011 Gephi Authors : Mathieu Jacomy <mathieu.jacomy@gmail.com> Website : http://www.gephi.org Copyright 2011 Gephi Consortium. All rights reserved. Portions Copyrighted 2011 Gephi Consortium.
The contents of this file are subject to the terms of either the GNU General Public License Version 3 only (“GPL”) or the Common Development and Distribution License(“CDDL”) (collectively, the “License”). You may not use this file except in compliance with the License.