IPython Widgets + D3 Force Layout

By Miguel Vaz, July 2014

This is inspired by the work from

Jake Vanderplas:

http://nbviewer.ipython.org/urls/gist.githubusercontent.com/jakevdp/289be7d8c6e3a1248921/raw/0f265de9999efbe8c7ab9efe302dba0320b5ae8c/d3widget.ipynb

Jonathan Frederic

http://nbviewer.ipython.org/github/jdfreder/ipython-d3/tree/master/

as well as

http://stackoverflow.com/questions/9539294/adding-new-nodes-to-force-directed-layout?rq=1

It requires a Python kernel to run; that is, if you're looking at this on nbviewer it won't work!

  • creates a d3 force layout, exposing some of the layout properties
  • the whole graph is synchronized all at once using a Dict traitlet

TODO:


In [5]:
from ipywidgets import widgets
from IPython.display import display
from ipygraphwidgets.widgetforcelayout import GraphWidget

In [ ]:
!ls

In [2]:
import networkx as nx

mygraph = nx.random_graphs.binomial_graph(20, 0.15, directed=False)

In [3]:
g = GraphWidget(width=500, height=500, charge=-250)
display(g)

In [4]:
g.set_graph(mygraph)