[PYTHON] View dynamic graphs in Jupyter notebook. (Inline display of D3.js)

Often you're touching data in Jupyter and want to display the graph inline for visualization. Often

%matplotlib inline

I think that is enough.

However, there may be times when you see a graph that is too much data to read, or you want to see a cleaner diagram. So, I found a way to get a beautiful dynamic graph with Jupyter, so I tried it.

Please see the demo first.

↓ Distributed diagram that can be moved and scaled d3.gif

↓ Graph diagram connecting yourself with the people you follow on Twitter twitter8.gif

Specifically, the result of using a JavaScript library called D3.js (https://d3js.org/) that specializes in data visualization is displayed inline in Jupyter.

First, put an extension called py_d3 in the environment where jupyter is running. (Https://github.com/ResidentMario/py_d3)

pip install py_d3

Import it with jupyter notebook and load the extension.

import py_d3
%load_ext py_d3

That way, you can use D3.js by adding the magic %% d3 at the beginning of the cell.

%%d3

<g></g>

<script>
d3.select("g").text("Hello World");
</script>

When you enter and execute Screenshot from 2017-02-20 19-11-11.png

It is like this.

It can also read external JS files and CSS, so if you have created something in the past, you can execute it immediately. If you've used D3.js, you can imagine what you can do, but if you don't, you can use D3.js official website or py_d3's github README. will give you a feel for it. You can do more than you think.

Recommended Posts

View dynamic graphs in Jupyter notebook. (Inline display of D3.js)
View graphs inline in Jupyter Notebook
Display HTML in Jupyter notebook
Browser specification of Jupyter Notebook in Windows environment
Drawing a tree structure with D3.js in Jupyter Notebook
[Memo] Display Jupyter Notebook on PC in monospaced font (Mac)
About the garbled Japanese part of pandas-profiling in Jupyter notebook
Multiprocessing error in Jupyter Notebook
View PDF on Jupyter Notebook
Unable to display tensorboard in jupyter notebook on docker (solved)
Git management of Jupyter notebook (ipynb) differences in easy-to-read with JupyterLab
Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker
Real-time display of video acquired from webcam on Jupyter notebook (Python3)
Waveform display of audio in Python
Simply view the Jupyter notebook file
Separate display of Python graphs (memo)
Memory leak in Python Jupyter Lab (Notebook)?
Jupyter Notebook does not show matplotlib graphs
Display a list of alphabets in Python 3
How to execute commands in jupyter notebook
Display the graph of tensorBoard on jupyter
GPU check of PC on jupyter notebook
Display histogram / scatter plot on Jupyter Notebook
Jupyter Notebook Basics of how to use
[Jupyter Notebook memo] Display kanji with matplotlib
To output a value even in the middle of a cell with Jupyter Notebook
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
How to make the font width of jupyter notebook put in pyenv equal width