19

I have just found out about 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.

# 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.

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)

  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. Documentation doesn't tell anything beyond creating nodes, edges and graphs.

I have also found out about 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.

also Is there a way to send the file I have created in gephi back to python.

Please suggest.

PS: I have edited the entire question details so that it's easier to understand now (hopefully).

  • Do you want to have Gephi up and running while you are building your graph in Python, or can it just be a file you create with python and load to Gephi? – Yannis P. Mar 11 '16 at 15:01
  • @YannisP. Yeah, gephi can be running. But I want everything to be done by python. –  Mar 14 '16 at 07:19
  • Yes but do you want to stream from python to gephi? Otherwise you can just use networkx anf write your graph in gexf format which is gephi native – Yannis P. Mar 14 '16 at 07:35
  • 1
    Again it is a bit unclear what you want to do. You can open the gexf with gephi and do whatever processing you want unless this is something you want to avoid and obtain directly the graph drawing you would obtain with Gephi, directly from python. In that case please edit your post to make it more clear – Yannis P. Mar 14 '16 at 08:19
  • 1
    Actually, your question is not very clear... It seems you manage to create a graph in python and send it to gephi, so, what is your problem, exactly, in one sentence ? – cedbeu Mar 14 '16 at 08:38
  • Problem is I have to do all the work in python , but the visualization output from python's netowrkx is not as impressive as Gephi. So I want to do all the coding in python and borrow the visualizations from Gephi. Since I have to do this a lot of times and for a huge no of networks it should be automatic. I can't manually create graphs on Gephi, it should be done automatically by python (by sending instructions or files etc) –  Mar 14 '16 at 08:43

2 Answers2

15

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.

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)

The other options at this point are:

Frobbit
  • 1,652
  • 17
  • 30
2

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 here for 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.

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:

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

and pray for it to work.

Yannis P.
  • 2,745
  • 1
  • 24
  • 39