Python equivalent of D3.js

Eiyrioü von Kauyf picture Eiyrioü von Kauyf · Oct 19, 2012 · Viewed 103.6k times · Source

Can anyone recommend a Python library that can do interactive graph visualization?

I specifically want something like d3.js but for python and ideally it would be 3D as well.

I have looked at:

  • NetworkX - it only does Matplotlib plots and those seem to be 2D. I didn't see any sort of interactiveness, like one that d3.js gives, such as pulling nodes around.
  • graph-tool - it does only 2D plots and has very slow interactive graphs.

Answer

Vincent Agnus picture Vincent Agnus · Jan 6, 2013

You could use d3py a python module that generate xml pages embedding d3.js script. For example :

import d3py
import networkx as nx

import logging
logging.basicConfig(level=logging.DEBUG)

G = nx.Graph()
G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(3,2)
G.add_edge(3,4)
G.add_edge(4,2)

# use 'with' if you are writing a script and want to serve this up forever
with d3py.NetworkXFigure(G, width=500, height=500) as p:
    p += d3py.ForceLayout()
    p.show()