简体   繁体   English

如何从Python创建Gephi网络图?

[英]How to create Gephi network graphs from Python?

I have just found out about GephiStreamer. 我刚刚发现了GephiStreamer。 https://pypi.python.org/pypi/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. 同样,我想通过Python在Gephi中完成所有工作。 Here is what I typically do. 这是我通常做的。

ex: 例如:

steps: 脚步:

  1. load nodes 加载节点

  2. load edges 加载边缘

  3. calculate betweeness centrality 计算好的中心性

  4. change the size/color of nodes as per their centrality scores 根据中心分数更改节点的大小/颜色

  5. change the graph layout (such as forceatlas2) 更改图形布局(例如forceatlas2)

  6. give the output graph 给出输出图

Below is the output I have got manually, but I want to produce the same by sending instructions from python to Gephi. 下面是我手动输出的内容,但我想通过从python向Gephi发送指令来生成相同的内容。 Documentation doesn't tell anything beyond creating nodes, edges and graphs. 文档除了创建节点,边和图之外没有任何说明。

I have also found out about NetworKit. 我也发现了NetworKit。 https://networkit.iti.kit.edu/data/uploads/docs/NetworKit-Doc/python/html/gephi.html 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:我已经编辑了整个问题的详细信息,以便现在更容易理解(希望如此)。

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 GephiStreamer and 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: 此时的其他选项是:

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 , ie the available jar, from jython, check here for an example use. Facebook小组的人可能知道一些事情,但IMO最好的方法是从jython调用Gephi toolkit ,即可用的jar,在这里查看一个示例用法。 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. 问题是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. 所以我会编写一个脚本让我们称之为graph_construction.py ,它使用networkx,构造图形,然后将其写入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: 然后我会编写第二个脚本gephi.py ,它将在gephi中执行,然后让图表将图形写入pdf,然后执行以下操作:

python graph_construction.py | jython gephi.py output.pdf

and pray for it to work. 并祈祷它工作。

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

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