SlideShare une entreprise Scribd logo
1  sur  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!

Contenu connexe

Tendances

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
 
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
 

Tendances (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
 

En vedette

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
 

En vedette (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)
 

Similaire à 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
 
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
 
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
 
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
 

Similaire à 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
 

Dernier

Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Seán Kennedy
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Machine learning classification ppt.ppt
Machine learning classification  ppt.pptMachine learning classification  ppt.ppt
Machine learning classification ppt.pptamreenkhanum0307
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSINGmarianagonzalez07
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in collegessuser7a7cd61
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...GQ Research
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...ssuserf63bd7
 

Dernier (20)

Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...Student profile product demonstration on grades, ability, well-being and mind...
Student profile product demonstration on grades, ability, well-being and mind...
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Machine learning classification ppt.ppt
Machine learning classification  ppt.pptMachine learning classification  ppt.ppt
Machine learning classification ppt.ppt
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
Biometric Authentication: The Evolution, Applications, Benefits and Challenge...
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
 

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!