Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ResidentMario/py_d3
D3 block magic for Jupyter notebook.
https://github.com/ResidentMario/py_d3
d3 data-visualization jupyter jupyter-notebook
Last synced: about 2 months ago
JSON representation
D3 block magic for Jupyter notebook.
- Host: GitHub
- URL: https://github.com/ResidentMario/py_d3
- Owner: ResidentMario
- License: mit
- Created: 2016-08-28T03:38:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-02-20T00:55:57.000Z (almost 3 years ago)
- Last Synced: 2024-10-26T18:44:57.520Z (about 2 months ago)
- Topics: d3, data-visualization, jupyter, jupyter-notebook
- Language: Python
- Homepage:
- Size: 6.3 MB
- Stars: 451
- Watchers: 23
- Forks: 40
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-jupyter-resources - GitHub - 6% open · ⏱️ 20.02.2022): (Jupyter-magic拓展)
README
# py_d3 [![PyPi version](https://img.shields.io/pypi/v/py_d3.svg)](https://pypi.python.org/pypi/py_d3/) ![t](https://img.shields.io/badge/status-unmaintained-red.svg)
## Deprecation notice
The `py_d3` package has been retired. This package was only ever intended to work in the classical Jupyter Notebook environment, this has been replaced pretty much all applications by the more advanced and more feature-complete Jupyter Lab. Jupyter Lab has a completely different SDK for notebook extensions, which this package neither uses nor supports.
As such this package is now unmaintained.
For users looking for an interactive environment for building D3.JS visualizations in, I recommend [Observable Notebooks](https://observablehq.com/explore).
For users looking to embed D3.JS visualizations in their Jupyter Lab notebooks, [check out this Gist](https://gist.github.com/gnestor/f1893e0226ced227e910f11b769adc06).
Happy plotting!
## About
`py_d3` is an IPython extension which adds D3 support to the Jupyter Notebook environment.
D3 is a powerful JavaScript data visualization library, while Jupyter is an intuitive browser-hosted Python
development environment. Wouldn't it be great if you could use them together? Now you can.## Quickstart
You can install `py_d3` by running `pip install py_d3`. Then load it into a Jupyter notebook by
running`%load_ext py_d3`.Use the `%%d3` [cell magic](http://ipython.readthedocs.io/en/stable/config/extensions/index.html#ipython-extensions)
to define notebook cells with D3 content.![alt text](./figures/import-py-d3-example.png "Logo Title Text 1")
`py_d3` allows you to express even very complex visual ideas within a Jupyter Notebook without much difficulty.
A [Radial Reingold-Tilford Tree](http://bl.ocks.org/mbostock/4063550), for example:![alt text](./figures/radial-tree-example.png "Logo Title Text 1")
An interactive treemap ([original](http://bl.ocks.org/mbostock/4063582)):
![alt text](./figures/tree-diagram-example.gif "Logo Title Text 1")
Or even the entire [D3 Show Reel](https://bl.ocks.org/mbostock/1256572) animation:
![alt text](./figures/show-reel.gif "Logo Title Text 1")
For more examples refer to the [examples notebooks](https://github.com/ResidentMario/py_d3/tree/master/notebooks).
## Features
### Configuration
The cell magic will default to loading the latest stable version of D3.JS available online (via
[CDNJS](https://cdnjs.com/about); `[email protected]` at time of writing). To load a specific version, append the version
name to the command, e.g. `%%d3 "3.5.17"`. To load D3.JS from a local file pass the filepath, e.g.
`%%d3 "d3.v5.min.js"`.Only one version of D3.JS may be loaded at a time. Both `3.x` and `4.x` versions 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 `%d3 version`.### Documentation
Pages from the [D3 API Reference](https://github.com/d3/d3/blob/master/API.md) may be rendered in-notebook using
`%d3 doc`. For example, you can render the `d3-array` reference by running `%d3 doc "d3-array"`.### Verbose Mode
You can view code to-be-rendered using verbose mode: `%d3 -v`. This is helpful for debugging your application.
## Technical
### How it works
Jupyter notebooks allow executing arbitrary JavaScript code using `IPython.display.JavaScript`, however it makes no
effort to restrict the level of DOM objects accessible to executable code. `py_d3` works by restricting `d3` scope to
whatever cell you are running the code in, by monkey-patching the `d3.select` and `d3.selectAll` methods (see
[here](https://github.com/d3/d3/issues/2947) for why this works).### Porting
Most HTML-hosted D3 visualizations, even very complex ones, can be made to run inside of a Jupyter Notebook `%%d3` cell with just two modifications:
* Remove any D3 imports in the cell (e.g. ``).
* Make sure to create and append to a legal HTML document sub-element. `d3.select("body").append("g")` won't work.### Contributing
See `CONTRIBUTING.md` for instructions on how to contribute.