#!/usr/bin/env python # coding: utf-8 # # Custom D3.js Visualization in a Jupyter Notebook # # by Stefaan Lippens ([@soxofaan](https://twitter.com/soxofaan)), May 2018 # TL;DR: If you want to skip the detailed mumbo jumbo, go straight to the code example in the [conclusion](#All-together-now). # # # ## Introduction # # When doing data science in a Jupyter notebook, there are plenty # of options for the standard data visualization needs: # matplotlib, pandas, seaborn, bokeh, etc. # Occasionally you might be stuck in a situation where you can not # easily express the desired visualization with the # standard vocabulary provided by these tools. # In these cases I like to leverage the flexibility # of [D3.js](https://d3js.org/) to build a custom graph or diagram. # # # In this article, I'll discuss an approach how to # implement a **custom do-it-yourself D3.js visualization** in a **Jupyter Notebook**. # This topic is covered in some other places around the web, # but I couldn't find a complete approach that # connects all the dots and isn't too hackish. # # In particular, I'll try to keep these things in mind here: # # - Leverage the [existing Jupyter functionality](http://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/JavaScript%20Notebook%20Extensions.html), # like a [RequireJS](http://requirejs.org/) environment # to have clean dependency handling # and to avoid `