D3 block magic for Jupyter notebook.
py_d3is an IPython extension which adds D3 support to the Jupyter Notebook environment.
You can install
pip install py_d3. Then load it into a Jupyter notebook by running
%%d3cell magic to define notebook cells with D3 content.
py_d3allows you to express even very complex visual ideas within a Jupyter Notebook without much difficulty. A Radial Reingold-Tilford Tree, for example:
An interactive treemap (original):
Or even the entire D3 Show Reel animation:
For more examples refer to the examples notebooks.
The cell magic will default to loading the latest stable version of D3.JS available online (via CDNJS;
%%d3 "3.5.17". To load D3.JS from a local file pass the filepath, e.g.
Only one version of D3.JS may be loaded at a time. Both
4.xversions of D3 are supported, but you may only run one version of D3 per notebook. You can check which versions are available by running
%d3 versions, and check which version is loaded in the current notebook using
Pages from the D3 API Reference may be rendered in-notebook using
%d3 doc. For example, you can render the
d3-arrayreference by running
%d3 doc "d3-array".
You can view code to-be-rendered using verbose mode:
%d3 -v. This is helpful for debugging your application.
py_d3works by restricting
d3scope to whatever cell you are running the code in, by monkey-patching the
d3.selectAllmethods (see here for why this works).
Most HTML-hosted D3 visualizations, even very complex ones, can be made to run inside of a Jupyter Notebook
%%d3cell with just two modifications:
CONTRIBUTING.mdfor instructions on how to contribute. Pull requests are welcome!