SlideShare a Scribd company logo
1 of 23
Brian Coffey
Data Scientist, Stitch Fix
PyData NYC 2015
D3 in Jupyter
https://github.com/stitchfix/d3-jupyter-tutorial
Overview
1. Why you may occasionally wish to do this (but likely not all the time)
2. Hello DOM!
3. Meet bl.ocks.org, I think youโ€™ll be great friends
4. A simple D3 scatterplot in Jupyter
5. A bar chart with interactivity (hello again DOM!)
6. Networks, maps and more
7. D3_lib.py (if you want to)
8. Discussion: From sketch to notebook frame
Why not all the time?
matplotlib, mpld3, bokeh, seaborn, toyplot, vispy, vincent, โ€ฆ
1. Why you may occasionally wish to do this (but likely not all the time)
Why not all the time?
matplotlib, mpld3, bokeh, seaborn, toyplot, vispy, vincent, โ€ฆ
Okay. Then why bother at all?
1. Maybe you just want the ultimate freedom in your data visualization, and
you happen to have some extra time on your hands, and/or you happen
to be a D3 wiz.
2. Maybe the perfect visualization for your analytical needs is not readily
available with other graphing tools, but there is a D3 example out there
that would be perfect with just some minor tweaks.
3. Maybe you are collaborating with a front-end person on a custom viz
1. Why you may occasionally wish to do this (but likely not all the time)
Just a heads up before we dig in.
If you are not already familiar with html, css and javascript, your eyes may
glaze over a bit during the first part of this tutorial.
But get what you can out of it, as understanding how it works will help you
to make the most of D3 in your Jupyter notebooks. I will try to be very clear
on the essential pieces of information you need to function, and on the
major gotchas for troubleshooting.
And if you get too lost, fear not. At the other end, there is a small helper
library and a collection of examples that you can use straight out of the box.
https://github.com/stitchfix/d3-jupyter-tutorial
2. Hello DOM!
โ€œOh, you can just call me Document Object Model for shortโ€
Check me out in your browserโ€™s development tools. Highlight a particular
element using the magnifying glass.
notebook: hello_dom.ipynb
from IPython.core.display import HTML
HTML( โ€˜<h1>Hello DOM!</h1>โ€™ )
in general โ€ฆ HTML( [insert a html string here and I will put it in the DOM] )
(I will put it in the div assigned to the output_result of the code block that I am in.)
2. Hello DOM! hello_dom.ipynb
Letโ€™s add some styleโ€ฆ
HTML(โ€˜
<style> โ€ฆ </style>
<h1 class=โ€œsteelyโ€>Hello DOM!</h1>โ€™)
2. Hello DOM! hello_dom.ipynb
And some javascript to modify the newly-added DOM element
HTML( โ€˜โ€ฆ
<h1 class=โ€œsteelyโ€ id=โ€œsteely-DOMโ€>Hello DOM!</h1>
<script>$(โ€˜steely-DOMโ€™).text(โ€œHello JavaScript!!!โ€)</script>โ€™)
2. Hello DOM! hello_dom.ipynb
Great. But how does D3 fit into this?
D3 is a JavaScript library. The Ds are for Data Driven Documents.
Think โ€˜Data Driven DOMโ€™.
A core aspect of using the D3 library is the following pattern:
1. Select some array of DOM elements
Note that this may be an empty array
2. โ€˜Attachโ€™ an array of data to that array of DOM elements
The array lengths need not match. Extra data may โ€˜enterโ€™, or DOM elements may โ€˜exitโ€™. D3
coordinates all of this with elegance.
3. Perform some actions for each element in the data array
This will generally involve modifying the selected DOM elements, or removing or appending
new DOM elements, based on the values of the data array.
2. Hello DOM! hello_dom.ipynb
Appending elements to the DOM with D3
2. Hello DOM! hello_dom.ipynb
Just one last step โ€“ writing data from Python into the JavaScript for use by
D3
2. Hello DOM! hello_dom.ipynb
A Brief Review of Key Points:
IPython.core.display.HTML allows you to directly write new DOM elements
With that HTML function, we can add css (<style>) and javascript (<script>)
elements, as well as <div> elements (or <h1> elements, etc) for them to act
on
D3 is a clever javascript library for DOM modification based on arrays of
data
We can write python data directly into <script> element text so that it can be
acted upon by D3.
2. Hello DOM! hello_dom.ipynb
for any late-joiners:
https://github.com/stitchfix/d3-jupyter-tutorial
A Brief Review of Key Points:
IPython.core.display.HTML allows you to directly write new DOM elements
With that HTML function, we can add css (<style>) and javascript (<script>)
elements, as well as <div> elements (or <h1> elements, etc) for them to act
on
D3 is a clever javascript library for DOM modification based on arrays of
data
We can write python data directly into <script> element text so that it can be
acted upon by D3.
2. Hello DOM! hello_dom.ipynb
https://github.com/stitchfix/d3-jupyter-tutorial
Sure. Great. But I havenโ€™t seen any data visualizations yetโ€ฆ
3. Meet bl.ocks.org, I think youโ€™ll be great friends
http://bl.ocks.org/mbostock/4063269http://bl.ocks.org/mbostock/1353700http://bl.ocks.org/mbostock/4060954
d3js.org , bl.ocks.org/mbostock
(And welcome to data visualization heaven)
http://bl.ocks.org/mbostock/4060954
Anatomy of a bl.ock
Pretty graphic, often interactive
Short description
html, css and javascript that
produces the graphic
data that gets read by script,
usually in csv or tsv form
3. Meet bl.ocks.org, I think youโ€™ll be great friends
Using this bl.ocks example: http://bl.ocks.org/mbostock/3887118
We will produce this in Jupyter:
4. A simple D3 scatterplot in Jupyter iris_scatterplot.ipynb
5. A bar chart with interactivity bar_chart_with_update.ipynb
(hello again DOM!)
watch out for the twistโ€ฆ
6. Networks, maps and more
sigma_js_graph.ipynb
temperature_histories.ipynb
polyFill_d3.ipynb
3d_meshing.ipynb
7. D3_lib.py (if you want to) multiple_simple_examples.ipynb
We have encapsulated a lot of the boilerplate for this method into an
external python file, which in turn calls external files containing your css
and js templates.
This just helps to keep things visually clean.
Feel free to use it as is and/or modify it to suit your needs.
8. Discussion: From sketch to notebook frame randomized_sketch.ipynb
Data Science @ Stitch
Fixbcoffey@stitchfix.com multithreaded.stitchfix.com
Thank you!

More Related Content

What's hot

Pythonpresent
PythonpresentPythonpresent
PythonpresentChui-Wen Chiu
ย 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
ย 
TensorFlow.Data ๋ฐ TensorFlow Hub
TensorFlow.Data ๋ฐ TensorFlow HubTensorFlow.Data ๋ฐ TensorFlow Hub
TensorFlow.Data ๋ฐ TensorFlow HubJeongkyu Shin
ย 
An Introduction to TensorFlow architecture
An Introduction to TensorFlow architectureAn Introduction to TensorFlow architecture
An Introduction to TensorFlow architectureMani Goswami
ย 
Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2Jay Coskey
ย 
Pitfalls of object_oriented_programming_gcap_09
Pitfalls of object_oriented_programming_gcap_09Pitfalls of object_oriented_programming_gcap_09
Pitfalls of object_oriented_programming_gcap_09Royce Lu
ย 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanicselliando dias
ย 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaEdureka!
ย 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++Mike Acton
ย 
refORM: Death to ORMs in .NET
refORM: Death to ORMs in .NETrefORM: Death to ORMs in .NET
refORM: Death to ORMs in .NETJames Hughes
ย 
FireWorks workflow software
FireWorks workflow softwareFireWorks workflow software
FireWorks workflow softwareAnubhav Jain
ย 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data ParallelismSasha Goldshtein
ย 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework XtextSebastian Zarnekow
ย 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Hermann Hueck
ย 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internalHyunghun Cho
ย 

What's hot (20)

Pythonpresent
PythonpresentPythonpresent
Pythonpresent
ย 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
ย 
TensorFlow.Data ๋ฐ TensorFlow Hub
TensorFlow.Data ๋ฐ TensorFlow HubTensorFlow.Data ๋ฐ TensorFlow Hub
TensorFlow.Data ๋ฐ TensorFlow Hub
ย 
An Introduction to TensorFlow architecture
An Introduction to TensorFlow architectureAn Introduction to TensorFlow architecture
An Introduction to TensorFlow architecture
ย 
Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2
ย 
Pitfalls of object_oriented_programming_gcap_09
Pitfalls of object_oriented_programming_gcap_09Pitfalls of object_oriented_programming_gcap_09
Pitfalls of object_oriented_programming_gcap_09
ย 
NANO266 - Lecture 9 - Tools of the Modeling Trade
NANO266 - Lecture 9 - Tools of the Modeling TradeNANO266 - Lecture 9 - Tools of the Modeling Trade
NANO266 - Lecture 9 - Tools of the Modeling Trade
ย 
MAVRL Workshop 2014 - pymatgen-db & custodian
MAVRL Workshop 2014 - pymatgen-db & custodianMAVRL Workshop 2014 - pymatgen-db & custodian
MAVRL Workshop 2014 - pymatgen-db & custodian
ย 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
ย 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | Edureka
ย 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
ย 
refORM: Death to ORMs in .NET
refORM: Death to ORMs in .NETrefORM: Death to ORMs in .NET
refORM: Death to ORMs in .NET
ย 
FireWorks workflow software
FireWorks workflow softwareFireWorks workflow software
FireWorks workflow software
ย 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
ย 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
ย 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
ย 
Textual Modeling Framework Xtext
Textual Modeling Framework XtextTextual Modeling Framework Xtext
Textual Modeling Framework Xtext
ย 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
ย 
Tensorflow internal
Tensorflow internalTensorflow internal
Tensorflow internal
ย 
Perl-C/C++ Integration with Swig
Perl-C/C++ Integration with SwigPerl-C/C++ Integration with Swig
Perl-C/C++ Integration with Swig
ย 

Viewers also liked

Unsupervised Computer Vision: The Current State of the Art
Unsupervised Computer Vision: The Current State of the ArtUnsupervised Computer Vision: The Current State of the Art
Unsupervised Computer Vision: The Current State of the ArtTJ Torres
ย 
Jupyter Kernel: How to Speak in Another Language
Jupyter Kernel: How to Speak in Another LanguageJupyter Kernel: How to Speak in Another Language
Jupyter Kernel: How to Speak in Another LanguageWey-Han Liaw
ย 
Interactive Data Visualization (with D3.js)
Interactive Data Visualization (with D3.js)Interactive Data Visualization (with D3.js)
Interactive Data Visualization (with D3.js)Lynn Cherny
ย 
Jupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at ScaleJupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at ScaleMatthias Bussonnier
ย 
Introduction to data visualisations with d3.js โ€” Data Driven Documents
Introduction to data visualisations with d3.js โ€” Data Driven DocumentsIntroduction to data visualisations with d3.js โ€” Data Driven Documents
Introduction to data visualisations with d3.js โ€” Data Driven DocumentsMichaล‚ Oniszczuk
ย 
Big Data visualization with Apache Spark and Zeppelin
Big Data visualization with Apache Spark and ZeppelinBig Data visualization with Apache Spark and Zeppelin
Big Data visualization with Apache Spark and Zeppelinprajods
ย 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with DataSeth Familian
ย 
Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...
Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...
Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...John Fonner
ย 
Data to Go: Mobile API Design
Data to Go: Mobile API DesignData to Go: Mobile API Design
Data to Go: Mobile API DesignChuck Greb
ย 
Building Mobile Dashboards With D3 and Google Charts
Building Mobile Dashboards With D3 and Google ChartsBuilding Mobile Dashboards With D3 and Google Charts
Building Mobile Dashboards With D3 and Google ChartsSalesforce Developers
ย 
The Compatibility Challenge:Examining R and Developing TERR
The Compatibility Challenge:Examining R and Developing TERRThe Compatibility Challenge:Examining R and Developing TERR
The Compatibility Challenge:Examining R and Developing TERRLou Bajuk
ย 
Veracity Embracing Uncertainty
Veracity Embracing UncertaintyVeracity Embracing Uncertainty
Veracity Embracing UncertaintyGalen Murdock
ย 
OSINT using Twitter & Python
OSINT using Twitter & PythonOSINT using Twitter & Python
OSINT using Twitter & Python37point2
ย 
Introduction to data visualisation with D3
Introduction to data visualisation with D3Introduction to data visualisation with D3
Introduction to data visualisation with D3Aleksander Fabijan
ย 
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.Graham Dumpleton
ย 
JupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸ
JupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸJupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸ
JupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸtaka400k
ย 
Examples of D3 Visualizations
Examples of D3 VisualizationsExamples of D3 Visualizations
Examples of D3 VisualizationsMD AMAN KHAN
ย 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tipsLearningTech
ย 
Advanced D3 Charting
Advanced D3 ChartingAdvanced D3 Charting
Advanced D3 Chartingdcryan
ย 
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)Future Insights
ย 

Viewers also liked (20)

Unsupervised Computer Vision: The Current State of the Art
Unsupervised Computer Vision: The Current State of the ArtUnsupervised Computer Vision: The Current State of the Art
Unsupervised Computer Vision: The Current State of the Art
ย 
Jupyter Kernel: How to Speak in Another Language
Jupyter Kernel: How to Speak in Another LanguageJupyter Kernel: How to Speak in Another Language
Jupyter Kernel: How to Speak in Another Language
ย 
Interactive Data Visualization (with D3.js)
Interactive Data Visualization (with D3.js)Interactive Data Visualization (with D3.js)
Interactive Data Visualization (with D3.js)
ย 
Jupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at ScaleJupyter, A Platform for Data Science at Scale
Jupyter, A Platform for Data Science at Scale
ย 
Introduction to data visualisations with d3.js โ€” Data Driven Documents
Introduction to data visualisations with d3.js โ€” Data Driven DocumentsIntroduction to data visualisations with d3.js โ€” Data Driven Documents
Introduction to data visualisations with d3.js โ€” Data Driven Documents
ย 
Big Data visualization with Apache Spark and Zeppelin
Big Data visualization with Apache Spark and ZeppelinBig Data visualization with Apache Spark and Zeppelin
Big Data visualization with Apache Spark and Zeppelin
ย 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
ย 
Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...
Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...
Jupyter Ascending: a practical hand guide to galactic scale, reproducible dat...
ย 
Data to Go: Mobile API Design
Data to Go: Mobile API DesignData to Go: Mobile API Design
Data to Go: Mobile API Design
ย 
Building Mobile Dashboards With D3 and Google Charts
Building Mobile Dashboards With D3 and Google ChartsBuilding Mobile Dashboards With D3 and Google Charts
Building Mobile Dashboards With D3 and Google Charts
ย 
The Compatibility Challenge:Examining R and Developing TERR
The Compatibility Challenge:Examining R and Developing TERRThe Compatibility Challenge:Examining R and Developing TERR
The Compatibility Challenge:Examining R and Developing TERR
ย 
Veracity Embracing Uncertainty
Veracity Embracing UncertaintyVeracity Embracing Uncertainty
Veracity Embracing Uncertainty
ย 
OSINT using Twitter & Python
OSINT using Twitter & PythonOSINT using Twitter & Python
OSINT using Twitter & Python
ย 
Introduction to data visualisation with D3
Introduction to data visualisation with D3Introduction to data visualisation with D3
Introduction to data visualisation with D3
ย 
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
Hear no evil, see no evil, patch no evil: Or, how to monkey-patch safely.
ย 
JupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸ
JupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸJupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸ
JupyterใฎๆฉŸ่ƒฝใ‚’ๆ‹กๅผตใ—ใฆใฟใŸ
ย 
Examples of D3 Visualizations
Examples of D3 VisualizationsExamples of D3 Visualizations
Examples of D3 Visualizations
ย 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
ย 
Advanced D3 Charting
Advanced D3 ChartingAdvanced D3 Charting
Advanced D3 Charting
ย 
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)
THE DATA DRIVEN WEB OF NOW: EXTENDING D3JS (Travis Smith)
ย 

Similar to D3 in Jupyter : PyData NYC 2015

Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)YangJerng Hwa
ย 
Dojo: Getting Started Today
Dojo: Getting Started TodayDojo: Getting Started Today
Dojo: Getting Started TodayGabriel Hamilton
ย 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1benDesigning
ย 
Advanced Module development
Advanced Module developmentAdvanced Module development
Advanced Module developmentdrupalindia
ย 
Breaking first-normal form with Hive
Breaking first-normal form with HiveBreaking first-normal form with Hive
Breaking first-normal form with HiveEdward Capriolo
ย 
Test02
Test02Test02
Test02testingPdf
ย 
HTML literals, the JSX of the platform
HTML literals, the JSX of the platformHTML literals, the JSX of the platform
HTML literals, the JSX of the platformKenneth Rohde Christiansen
ย 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?Colin Riley
ย 
A Quick and Dirty D3.js Tutorial
A Quick and Dirty D3.js TutorialA Quick and Dirty D3.js Tutorial
A Quick and Dirty D3.js TutorialYoung-Ho Kim
ย 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module DevelopmentSumeet Pareek
ย 
Untangling7
Untangling7Untangling7
Untangling7Derek Jacoby
ย 
Theme customisation for beginners
Theme customisation for beginnersTheme customisation for beginners
Theme customisation for beginnersGareth J Barnard
ย 
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018Esteve Castells
ย 
All of javascript
All of javascriptAll of javascript
All of javascriptTogakangaroo
ย 
Forensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonForensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonEmma Jane Hogbin Westby
ย 
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify Dataconomy Media
ย 
The Data Janitor Returns | Daniel Molnar | DN18
The Data Janitor Returns | Daniel Molnar | DN18The Data Janitor Returns | Daniel Molnar | DN18
The Data Janitor Returns | Daniel Molnar | DN18DataconomyGmbH
ย 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
ย 
Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2ice799
ย 

Similar to D3 in Jupyter : PyData NYC 2015 (20)

Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)
ย 
Dojo: Getting Started Today
Dojo: Getting Started TodayDojo: Getting Started Today
Dojo: Getting Started Today
ย 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
ย 
Advanced Module development
Advanced Module developmentAdvanced Module development
Advanced Module development
ย 
Breaking first-normal form with Hive
Breaking first-normal form with HiveBreaking first-normal form with Hive
Breaking first-normal form with Hive
ย 
Test02
Test02Test02
Test02
ย 
HTML literals, the JSX of the platform
HTML literals, the JSX of the platformHTML literals, the JSX of the platform
HTML literals, the JSX of the platform
ย 
What does OOP stand for?
What does OOP stand for?What does OOP stand for?
What does OOP stand for?
ย 
A Quick and Dirty D3.js Tutorial
A Quick and Dirty D3.js TutorialA Quick and Dirty D3.js Tutorial
A Quick and Dirty D3.js Tutorial
ย 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
ย 
Untangling7
Untangling7Untangling7
Untangling7
ย 
Theme customisation for beginners
Theme customisation for beginnersTheme customisation for beginners
Theme customisation for beginners
ย 
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
Advanced Web Scraping or How To Make Internet Your Database #seoplus2018
ย 
All of javascript
All of javascriptAll of javascript
All of javascript
ย 
Forensic Theming - DrupalCon London
Forensic Theming - DrupalCon LondonForensic Theming - DrupalCon London
Forensic Theming - DrupalCon London
ย 
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify
DN18 | The Data Janitor Returns | Daniel Molnar | Oberlo/Shopify
ย 
The Data Janitor Returns | Daniel Molnar | DN18
The Data Janitor Returns | Daniel Molnar | DN18The Data Janitor Returns | Daniel Molnar | DN18
The Data Janitor Returns | Daniel Molnar | DN18
ย 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
ย 
Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2Infrastructure as code might be literally impossible part 2
Infrastructure as code might be literally impossible part 2
ย 
Shifting Gears
Shifting GearsShifting Gears
Shifting Gears
ย 

Recently uploaded

Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxchadhar227
ย 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.pptibrahimabdi22
ย 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
ย 
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book nowgargpaaro
ย 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...Health
ย 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...nirzagarg
ย 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...SOFTTECHHUB
ย 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraGovindSinghDasila
ย 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabiaahmedjiabur940
ย 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...nirzagarg
ย 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
ย 
Kings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about themKings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about themeitharjee
ย 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...gajnagarg
ย 
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...HyderabadDolls
ย 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubaikojalkojal131
ย 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
ย 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...gajnagarg
ย 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...kumargunjan9515
ย 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
ย 

Recently uploaded (20)

Gartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptxGartner's Data Analytics Maturity Model.pptx
Gartner's Data Analytics Maturity Model.pptx
ย 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
ย 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
ย 
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara ๐Ÿ’‹ Call Girl 7737669865 Call Girls in Vadodara Escort service book now
ย 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
ย 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
ย 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
ย 
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
TrafficWave Generator Will Instantly drive targeted and engaging traffic back...
ย 
Aspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - AlmoraAspirational Block Program Block Syaldey District - Almora
Aspirational Block Program Block Syaldey District - Almora
ย 
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi ArabiaIn Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
In Riyadh ((+919101817206)) Cytotec kit @ Abortion Pills Saudi Arabia
ย 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
ย 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
ย 
Kings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about themKings of Saudi Arabia, information about them
Kings of Saudi Arabia, information about them
ย 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
ย 
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
Jodhpur Park | Call Girls in Kolkata Phone No 8005736733 Elite Escort Service...
ย 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
ย 
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Vadodara [ 7014168258 ] Call Me For Genuine Models ...
ย 
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Indore [ 7014168258 ] Call Me For Genuine Models We...
ย 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
ย 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
ย 

D3 in Jupyter : PyData NYC 2015

  • 1. Brian Coffey Data Scientist, Stitch Fix PyData NYC 2015 D3 in Jupyter
  • 3. Overview 1. Why you may occasionally wish to do this (but likely not all the time) 2. Hello DOM! 3. Meet bl.ocks.org, I think youโ€™ll be great friends 4. A simple D3 scatterplot in Jupyter 5. A bar chart with interactivity (hello again DOM!) 6. Networks, maps and more 7. D3_lib.py (if you want to) 8. Discussion: From sketch to notebook frame
  • 4. Why not all the time? matplotlib, mpld3, bokeh, seaborn, toyplot, vispy, vincent, โ€ฆ 1. Why you may occasionally wish to do this (but likely not all the time)
  • 5. Why not all the time? matplotlib, mpld3, bokeh, seaborn, toyplot, vispy, vincent, โ€ฆ Okay. Then why bother at all? 1. Maybe you just want the ultimate freedom in your data visualization, and you happen to have some extra time on your hands, and/or you happen to be a D3 wiz. 2. Maybe the perfect visualization for your analytical needs is not readily available with other graphing tools, but there is a D3 example out there that would be perfect with just some minor tweaks. 3. Maybe you are collaborating with a front-end person on a custom viz 1. Why you may occasionally wish to do this (but likely not all the time)
  • 6. Just a heads up before we dig in. If you are not already familiar with html, css and javascript, your eyes may glaze over a bit during the first part of this tutorial. But get what you can out of it, as understanding how it works will help you to make the most of D3 in your Jupyter notebooks. I will try to be very clear on the essential pieces of information you need to function, and on the major gotchas for troubleshooting. And if you get too lost, fear not. At the other end, there is a small helper library and a collection of examples that you can use straight out of the box. https://github.com/stitchfix/d3-jupyter-tutorial
  • 7. 2. Hello DOM! โ€œOh, you can just call me Document Object Model for shortโ€ Check me out in your browserโ€™s development tools. Highlight a particular element using the magnifying glass. notebook: hello_dom.ipynb
  • 8. from IPython.core.display import HTML HTML( โ€˜<h1>Hello DOM!</h1>โ€™ ) in general โ€ฆ HTML( [insert a html string here and I will put it in the DOM] ) (I will put it in the div assigned to the output_result of the code block that I am in.) 2. Hello DOM! hello_dom.ipynb
  • 9. Letโ€™s add some styleโ€ฆ HTML(โ€˜ <style> โ€ฆ </style> <h1 class=โ€œsteelyโ€>Hello DOM!</h1>โ€™) 2. Hello DOM! hello_dom.ipynb
  • 10. And some javascript to modify the newly-added DOM element HTML( โ€˜โ€ฆ <h1 class=โ€œsteelyโ€ id=โ€œsteely-DOMโ€>Hello DOM!</h1> <script>$(โ€˜steely-DOMโ€™).text(โ€œHello JavaScript!!!โ€)</script>โ€™) 2. Hello DOM! hello_dom.ipynb
  • 11. Great. But how does D3 fit into this? D3 is a JavaScript library. The Ds are for Data Driven Documents. Think โ€˜Data Driven DOMโ€™. A core aspect of using the D3 library is the following pattern: 1. Select some array of DOM elements Note that this may be an empty array 2. โ€˜Attachโ€™ an array of data to that array of DOM elements The array lengths need not match. Extra data may โ€˜enterโ€™, or DOM elements may โ€˜exitโ€™. D3 coordinates all of this with elegance. 3. Perform some actions for each element in the data array This will generally involve modifying the selected DOM elements, or removing or appending new DOM elements, based on the values of the data array. 2. Hello DOM! hello_dom.ipynb
  • 12. Appending elements to the DOM with D3 2. Hello DOM! hello_dom.ipynb
  • 13. Just one last step โ€“ writing data from Python into the JavaScript for use by D3 2. Hello DOM! hello_dom.ipynb
  • 14. A Brief Review of Key Points: IPython.core.display.HTML allows you to directly write new DOM elements With that HTML function, we can add css (<style>) and javascript (<script>) elements, as well as <div> elements (or <h1> elements, etc) for them to act on D3 is a clever javascript library for DOM modification based on arrays of data We can write python data directly into <script> element text so that it can be acted upon by D3. 2. Hello DOM! hello_dom.ipynb for any late-joiners: https://github.com/stitchfix/d3-jupyter-tutorial
  • 15. A Brief Review of Key Points: IPython.core.display.HTML allows you to directly write new DOM elements With that HTML function, we can add css (<style>) and javascript (<script>) elements, as well as <div> elements (or <h1> elements, etc) for them to act on D3 is a clever javascript library for DOM modification based on arrays of data We can write python data directly into <script> element text so that it can be acted upon by D3. 2. Hello DOM! hello_dom.ipynb https://github.com/stitchfix/d3-jupyter-tutorial Sure. Great. But I havenโ€™t seen any data visualizations yetโ€ฆ
  • 16. 3. Meet bl.ocks.org, I think youโ€™ll be great friends http://bl.ocks.org/mbostock/4063269http://bl.ocks.org/mbostock/1353700http://bl.ocks.org/mbostock/4060954 d3js.org , bl.ocks.org/mbostock (And welcome to data visualization heaven)
  • 17. http://bl.ocks.org/mbostock/4060954 Anatomy of a bl.ock Pretty graphic, often interactive Short description html, css and javascript that produces the graphic data that gets read by script, usually in csv or tsv form 3. Meet bl.ocks.org, I think youโ€™ll be great friends
  • 18. Using this bl.ocks example: http://bl.ocks.org/mbostock/3887118 We will produce this in Jupyter: 4. A simple D3 scatterplot in Jupyter iris_scatterplot.ipynb
  • 19. 5. A bar chart with interactivity bar_chart_with_update.ipynb (hello again DOM!) watch out for the twistโ€ฆ
  • 20. 6. Networks, maps and more sigma_js_graph.ipynb temperature_histories.ipynb polyFill_d3.ipynb 3d_meshing.ipynb
  • 21. 7. D3_lib.py (if you want to) multiple_simple_examples.ipynb We have encapsulated a lot of the boilerplate for this method into an external python file, which in turn calls external files containing your css and js templates. This just helps to keep things visually clean. Feel free to use it as is and/or modify it to suit your needs.
  • 22. 8. Discussion: From sketch to notebook frame randomized_sketch.ipynb
  • 23. Data Science @ Stitch Fixbcoffey@stitchfix.com multithreaded.stitchfix.com Thank you!