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