如何从 Python 创建 Gephi 网络图?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35936991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create Gephi network graphs from Python?
提问by
I have just found out about GephiStreamer. https://pypi.python.org/pypi/GephiStreamer
我刚刚发现了 GephiStreamer。https://pypi.python.org/pypi/GephiStreamer
Using this package one can send instructions from python to Gephi to create nodes and edges in Gephi.
使用这个包可以从 python 向 Gephi 发送指令以在 Gephi 中创建节点和边。
# Create a node with a custom_property
node_a = graph.Node("A",custom_property=1)
# Create edge
edge_ab = graph.Edge(node_a,node_b,custom_property="hello")
stream.add_edge(edge_ab)
Similarly I want to do everything in Gephi through Python. Here is what I typically do.
同样,我想通过 Python 在 Gephi 中做所有事情。这是我通常做的事情。
ex:
前任:
steps:
脚步:
load nodes
load edges
calculate betweeness centrality
change the size/color of nodes as per their centrality scores
change the graph layout (such as forceatlas2)
give the output graph
负载节点
负载边
计算中间中心性
根据中心性分数更改节点的大小/颜色
更改图形布局(例如 forceatlas2)
给出输出图
Below is the output I have got manually, but I want to produce the same by sending instructions from python to Gephi. Documentation doesn't tell anything beyond creating nodes, edges and graphs.
下面是我手动获得的输出,但我想通过从 python 向 Gephi 发送指令来产生相同的输出。除了创建节点、边和图形之外,文档没有说明任何内容。
I have also found out about NetworKit. https://networkit.iti.kit.edu/data/uploads/docs/NetworKit-Doc/python/html/gephi.html
我还发现了有关 NetworKit 的信息。https://networkit.iti.kit.edu/data/uploads/docs/NetworKit-Doc/python/html/gephi.html
This is slightly better than gephistramer, but this requires python 3.4 or higher and most of the packages like pandas, numpy or sickit are in 2.7.
这比 gephistramer 稍好,但这需要 python 3.4 或更高版本,并且大多数包,如 pandas、numpy 或sickit 都在 2.7 中。
also Is there a way to send the file I have created in gephi back to python.
还有一种方法可以将我在 gephi 中创建的文件发送回 python。
Please suggest.
请建议。
PS: I have edited the entire question details so that it's easier to understand now (hopefully).
PS:我已经编辑了整个问题的详细信息,以便现在更容易理解(希望如此)。
回答by Frobbit
I found this question while looking for the answer myself. I picked Gephi as my visualizer and then wanted to build a graph that was well supported by the tool by pulling data from around my org with Python.
我在自己寻找答案时发现了这个问题。我选择 Gephi 作为我的可视化工具,然后想通过使用 Python 从我的组织中提取数据来构建一个受该工具良好支持的图形。
I found GephiStreamerand it looks a simple yet comprehensive way to build graphs in Gephi from an external python environment (command line, or IDE)
我找到了GephiStreamer,它看起来是一种从外部 Python 环境(命令行或 IDE)在 Gephi 中构建图形的简单而全面的方法
The other options at this point are:
此时的其他选项是:
- The Gephi Python Scripting Console
- Any Graph Lib that can export in a Gephi readable format
- Any of the python GEFX writers (Google "python GEFX")
- Gephi Python 脚本控制台
- 任何可以以Gephi 可读格式导出的图形库
- 任何 python GEFX 编写器(谷歌“python GEFX”)
回答by Yannis P.
There is no simple answer to that. The people at the Facebook group might be knowing something but IMO the best way to do it would be to call the Gephi toolkit
, i.e. the available jar, from jython, check herefor an example use. The thing is that jython doesn't allow to install numpy
and a series of other libraries but I guess you could get around this issue by piping the output of one script to the other or using a queue like Celery.
对此没有简单的答案。Facebook 组的人可能知道一些事情,但 IMO 最好的方法是调用Gephi toolkit
jython 中的 ,即可用的 jar,请在此处查看示例用法。问题是 jython 不允许安装numpy
和一系列其他库,但我想您可以通过将一个脚本的输出通过管道传输到另一个脚本或使用像 Celery 这样的队列来解决这个问题。
So I would write a script let's call it graph_construction.py
that uses networkx, construct the graph and then write it in the standard output in gexf. Then I would write a second script, gephi.py
that would execute things in gephi and let's say write the graph to a pdf and then do something like:
所以我会写一个脚本,让我们称之为graph_construction.py
使用 networkx的脚本,构建图形,然后将它写在 gexf 的标准输出中。然后我会写第二个脚本,gephi.py
它会在 gephi 中执行事情,假设将图形写入 pdf,然后执行以下操作:
python graph_construction.py | jython gephi.py output.pdf
and pray for it to work.
并祈祷它起作用。