SlideShare a Scribd company logo
1 of 21
Download to read offline
Getting more out of Matplotlib with GR
July 20th – 26th, 2015
Bilbao | EuroPython 2015 | Josef Heinen | @josef_heinen
MemberoftheHelmholtzAssociation
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
✓ visualize and analyzing two- and three-dimensional data sets
✓ plot 2D data for real-time monitoring purposes (signal processing)
✓ visualize large data sets, probably with a dynamic component, preferably in
real-time 
✓ create publication-quality and web-ready graphics
✓ create animations or videos on the fly
2
Visualization needs
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Python visualization solutions
Matplotlib — de-facto standard (“workhorse”)

➟ Browser solutions: Bokeh, plot.ly
Mayavi (mlab) — powerful, but overhead fromVTK
ggplot, chaco — statistical, 2D graphics
VTK — versatile, but difficult to learn
Vispy, Glumpy, OpenGL — fast, but low-level API
3
2D 3D
Bokeh
Plotly
ggplot
chaco
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
separated 2D and (hardware accelerated) 3D world
some graphics backends "only" produce "figures"

➟ no presentation of continuous data streams
speed up “only” by means of backend specific

code ➟ poor performance on large data sets
Problems so far — Crux of the matter
4
Quality
Interop
Speed
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
How can we improve the performance?
✓ Several Python modules can be compiled into native code, making them much
faster (Cython)
✓ Compiling hotspots on the fly (Numba, PyPy) can significantly speed up
numerical code segments
✓ Use hardware acceleration, but …
… these approaches cannot easily be applied to visualization software!

➟ Could another backend speedup Matplotlib and improve interop ?
5
Where to go from here?
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Use GR to achieve more graphics performance
✓ procedural graphics backend (completely written in C)

➟ presentation of continuous data streams
✓ builtin support for 2D plotting and OpenGL (GR3)

➟ coexistent 2D and 3D world
✓ interoperability with GUI toolkits and Web frameworks

➟ good user interaction
6
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Use GR to extend Matplotlib’s capabilities
✓ combine the power of Matplotlib and GR

➟ next Matplotlib release will allow selecting the backend by setting the
environment variable MPLBACKEND
✓ produce video contents on the fly by adding a single line of code

➟ no need to import an animation module or write extra code
✓ create plots containing both 2D and 3D graphics elements
7
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
How it works: GR layer architecture
GKS logical device drivers
C / C++
GKS
GR
OpenGL (WGL / CGL / GLX)
POV-Ray

generation
off-screen
rendering
direct
rendering
Browser
JavaScript

generation
WebGL
IPython
Win32X11
GKSTermgksqt LATEX
Qt Quartz PDF
C / ObjC
OpenGL ES
glgr / iGR App socket

communication
Qt / wx

event loop
0MQ OpenGL
More logical device drivers / plugins:
– CGM, GKSM, GIF, RF, UIL
– WMF, Xfig
– GS (BMP, JPEG, PNG,TIFF)
...
HTML5
wx
POV-Ray
GLUT
GLFW
wxGLCanvas
QGLWidget
...
SVGPS
MOV
GR3
Highlights:
– simultaneous output to multiple output devices
– direct generation of MPEG4 image sequences
– flicker-free display ("double buffering”)
– IPython / Jupyter notebook integration
TikZ
Swift
PyPy
Generate ray-traced
graphics scenes
Notebooks support for
Python or Julia kernels
Use GR as a Matplotlib
backend;

mix GR, MPL and GR3 code
Create HTML5
output
Qt console
interaction
Create video animations
on the fly
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Matplotlib using the GR backend
9
Circle
Rectangle
Wedge
Polygon
Ellipse
Arrow
PathPatch
FancyBoxPatch
Line2D
! % # % & ( * $#
+
! %
#
%
&
(
*
$#
$%
$&
$(
-
#"#
%"'
'"#
)"'
$#"#
$%"'
$'"#
$)"'
%#"#
%%"'
+,
'
%!
$!
#!
"!
!
"!
#!
$!
%!
(
%!
$!
#!
"!
!
"!
#!
$!
%!
)
"!!
&!
!
&!
"!!
# '$% # &$* # &$% # %$* %$% %$* &$% &$* '$%
# '$%
# &$*
# &$%
# %$*
%$%
%$*
&$%
&$*
'$%
051..-7- 7/67 !'%% 431276"
# %$(+
# %$')
# %$&'
%$%%
%$&'
%$')
%$(+
%$),
$"# $"( %"# %"( &"# &"( '"# '"( ("#
$"#
$"(
%"#
%"(
&"#
&"(
'"#
'"(
("#
4+30351,6. :/7. 0,9,06
! #"*
! #")
! #"&
#"#
#"&
#")
#"*
$"%
$"( %"# %"( &"# &"( '"# '"(
$"(
%"#
%"(
&"#
&"(
'"#
'"(
+327385- :/7. 0,9,06
! #"*
! #")
! #"&
#"#
#"&
#")
#"*
$"%
0°
45°
90°
135°
180°
225°
270°
315°
2
4
6
8
10
(
&
$
"
$
&
( (
&
$
"
$
&
(
#!"#
"!)+
"!'(
"!%&
"!##
"!##
"!%&
"!'(
"!)+
#!"#
"!*
"!(
"!&
"!$
"!"
"!$
"!&
"!(
"!*
# &$% # %$' %$% %$' &$%
# &$%
# %$'
%$%
%$'
&$%
)/07,5/2- * (,0*82*9 1,6.
!*440/+*7/32 73 ./-.# 5,63087/32 75/+327385/2-"
#!"
"!&
"!"
"!&
#!" #!"
"!&
"!"
"!&
#!"
"!'
"!%
"!$
"!"
"!$
"!%
"!'
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
GR in action …
10
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
GR / Jupyter
Performance
(anim.py)
0
100
200
300
400
500
600
700
MPL MPL+GR GR
fps
click images to view notebooks …
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Performance analysis
0
100
200
300
400
500
600
700
MPL MPL+GR GR
fps
ncalls cumtime filename:lineno(function)
398 6.852 {method'draw'of'_macosx.FigureCanvas'objects}
29378/397 6.771 artist.py:57(draw_wrapper)
397 6.769 figure.py:1004(draw)
397 6.574 _base.py:1989(draw)
794 5.894 axis.py:1106(draw)
5161 4.601 axis.py:232(draw)
199 3.616 pyplot.py:175(pause)
10719 3.609 lines.py:661(draw)
199 3.480 pyplot.py:551(draw)
7940 1.044 text.py:581(draw)
ncalls cumtime filename:lineno(function)
199 4.412 pyplot.py:551(draw)
199 4.410 backend_gr.py:227(draw)
14726/199 4.237 artist.py:57(draw_wrapper)
199 4.236 figure.py:1004(draw)
199 4.138 _base.py:1989(draw)
398 3.770 axis.py:1106(draw)
2587 3.073 axis.py:232(draw)
5373 2.642 lines.py:661(draw)
5174 1.202 backend_bases.py:237(draw_markers)
ncalls cumtime filename:lineno(function)
199 3.263 __init__.py:1910(plot)
199 3.184 __init__.py:250(updatews)
MPL
MPL + GR
GR
most time spent in
backend wrapper
???
No room for further
optimizations on the
backend side
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
GR + GR3 + Matplotlib interop
13
Matplotlib
GR3
GR
Important:
tells MPL backend not to update
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Inline graphics
Matplotlib
GR
~ 10 times faster
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Demos
✓ Animated graphics performance comparison: Matplotlib vs. GR
(anim.ipynb)
✓ GR / mogli / Matplotlib interoperability example (interop.ipynb)
✓ Inline graphics performance comparison: Matplotlib vs. GR
(inline.ipynb)
✓ Simple spectral (specgram.ipynb)
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
GR + GKS can be transpiled to JS

(Emscripten: LLVM-to-JavaScript compiler)


➟ Use cases:
✓ embed JS code in IP[y]: or IJulia (Jypyter)
✓ parse GKS JavaScript logical device driver

generated display list in browser
Outlook (GR release v0.15.0)
JavaScript
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
What else can GR be used for?
pyMolDyn
see Poster session: Embedding visualization applications with pygr by Christian Felder
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Conclusions
✓ Using the GR Matplotlib backend has not turned out satisfactory as the
speedups were not as expected
✓ GR adds more plotting capabilities to Matplotlib allowing to mix 2D drawings
and 3D graphics scenes or create movies on the fly
✓ Producing plots / figures is much faster with the GR framework (speedup for
plots > 20, > 100 respectively)
18
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
What happens next?
✓ integrate JavaScript GKS logical device driver
✓ provide more convenience function
✓ migrate the GR3 library to modern OpenGL (using OpenGL shader language)

➟ visualize millions of vertices / faces
✓ simplify the installation
19
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Resources
✓ Website: http://gr-framework.org
✓ GR framework: https://github.com/jheinen/gr
✓ PyPI: https://pypi.python.org/pypi/gr
✓ Talk material: Getting more out of Matplotlib with GR
20
July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems
Thank you for your attention
Questions?
Contact:
j.heinen@fz-juelich.de

@josef_heinen
Thanks to:
Fabian Beule, Steffen Drossard, Christian Felder, Marvin Goblet, Ingo Heimbach,
Daniel Kaiser, Philip Klinkhammer, David Knodt, Florian Rhiem, Jörg Winkler et al.
21

More Related Content

Viewers also liked

มีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลาย
มีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลายมีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลาย
มีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลาย
Manow Butnow
 
การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61
การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61
การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61
Manow Butnow
 
GR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GRGR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GR
Josef Heinen
 
Scientific Visualization
Scientific VisualizationScientific Visualization
Scientific Visualization
Josef Heinen
 

Viewers also liked (8)

มีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลาย
มีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลายมีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลาย
มีการนำอินเตอร์เน็ตไปประยุกต์ใช้งานหลากหลาย
 
การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61
การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61
การประกันชีวิต นางสาว ณัฏฐณิชา หุนสนธิ ม.61
 
ข้อสอบโอเน็ต
ข้อสอบโอเน็ตข้อสอบโอเน็ต
ข้อสอบโอเน็ต
 
อาชญากรรมวายร้าย
อาชญากรรมวายร้ายอาชญากรรมวายร้าย
อาชญากรรมวายร้าย
 
GR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GRGR.jl - Plotting for Julia based on GR
GR.jl - Plotting for Julia based on GR
 
Scientific Visualization
Scientific VisualizationScientific Visualization
Scientific Visualization
 
Getting more out of Matplotlib with GR
Getting more out of Matplotlib with GRGetting more out of Matplotlib with GR
Getting more out of Matplotlib with GR
 
การพัฒนาโครงงานคอมพิวเตอร์ประยุกต์ทางด้านธุรกิจ
การพัฒนาโครงงานคอมพิวเตอร์ประยุกต์ทางด้านธุรกิจการพัฒนาโครงงานคอมพิวเตอร์ประยุกต์ทางด้านธุรกิจ
การพัฒนาโครงงานคอมพิวเตอร์ประยุกต์ทางด้านธุรกิจ
 

Similar to Getting more out of Matplotlib with GR

Why Groovy is Game Changing
Why Groovy is Game ChangingWhy Groovy is Game Changing
Why Groovy is Game Changing
Kyle Goodfriend
 
DIY- computer vision with GWT
DIY- computer vision with GWTDIY- computer vision with GWT
DIY- computer vision with GWT
Francesca Tosi
 
iPhone/iPad Development with Titanium
iPhone/iPad Development with TitaniumiPhone/iPad Development with Titanium
iPhone/iPad Development with Titanium
Axway Appcelerator
 

Similar to Getting more out of Matplotlib with GR (20)

Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...
Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...
Automated ML Workflow for Distributed Big Data Using Analytics Zoo (CVPR2020 ...
 
Easy path to machine learning (Spring 2020)
Easy path to machine learning (Spring 2020)Easy path to machine learning (Spring 2020)
Easy path to machine learning (Spring 2020)
 
Why Groovy is Game Changing
Why Groovy is Game ChangingWhy Groovy is Game Changing
Why Groovy is Game Changing
 
Graph Gurus Episode 37: Modeling for Kaggle COVID-19 Dataset
Graph Gurus Episode 37: Modeling for Kaggle COVID-19 DatasetGraph Gurus Episode 37: Modeling for Kaggle COVID-19 Dataset
Graph Gurus Episode 37: Modeling for Kaggle COVID-19 Dataset
 
FITC 2013 - The Technical Learning Curve
FITC 2013 - The Technical Learning CurveFITC 2013 - The Technical Learning Curve
FITC 2013 - The Technical Learning Curve
 
Scaling graph investigations with Math, GPUs, & Experts
Scaling graph investigations with Math, GPUs, & ExpertsScaling graph investigations with Math, GPUs, & Experts
Scaling graph investigations with Math, GPUs, & Experts
 
CodeCamp Iasi - Creating serverless data analytics system on GCP using BigQuery
CodeCamp Iasi - Creating serverless data analytics system on GCP using BigQueryCodeCamp Iasi - Creating serverless data analytics system on GCP using BigQuery
CodeCamp Iasi - Creating serverless data analytics system on GCP using BigQuery
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
Introduction to serverless computing on Google Cloud
Introduction to serverless computing on Google CloudIntroduction to serverless computing on Google Cloud
Introduction to serverless computing on Google Cloud
 
DIY: Computer Vision with GWT.
DIY: Computer Vision with GWT.DIY: Computer Vision with GWT.
DIY: Computer Vision with GWT.
 
DIY- computer vision with GWT
DIY- computer vision with GWTDIY- computer vision with GWT
DIY- computer vision with GWT
 
CV - Jaspreet Singh
CV - Jaspreet SinghCV - Jaspreet Singh
CV - Jaspreet Singh
 
OWASP Juice Shop 5.x and beyond
OWASP Juice Shop 5.x and beyondOWASP Juice Shop 5.x and beyond
OWASP Juice Shop 5.x and beyond
 
GWAB Lyon - Legacy code atelier
GWAB Lyon - Legacy code atelierGWAB Lyon - Legacy code atelier
GWAB Lyon - Legacy code atelier
 
GeoPython - Mapping Data in Jupyter Notebooks with PixieDust
GeoPython - Mapping Data in Jupyter Notebooks with PixieDustGeoPython - Mapping Data in Jupyter Notebooks with PixieDust
GeoPython - Mapping Data in Jupyter Notebooks with PixieDust
 
iPhone/iPad Development with Titanium
iPhone/iPad Development with TitaniumiPhone/iPad Development with Titanium
iPhone/iPad Development with Titanium
 
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CA
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CAAppcelerator iPhone/iPad Dev Con 2010 San Diego, CA
Appcelerator iPhone/iPad Dev Con 2010 San Diego, CA
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 
Using Google (Cloud) APIs
Using Google (Cloud) APIsUsing Google (Cloud) APIs
Using Google (Cloud) APIs
 
UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)UberFire Quick Intro and Overview (early beta Aug 2013)
UberFire Quick Intro and Overview (early beta Aug 2013)
 

Recently uploaded

Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
ssuser79fe74
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
PirithiRaju
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
PirithiRaju
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
AlMamun560346
 
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
Lokesh Kothari
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Lokesh Kothari
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
Sérgio Sacani
 

Recently uploaded (20)

Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Chemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdfChemistry 4th semester series (krishna).pdf
Chemistry 4th semester series (krishna).pdf
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
 
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
❤Jammu Kashmir Call Girls 8617697112 Personal Whatsapp Number 💦✅.
 
Botany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdfBotany 4th semester series (krishna).pdf
Botany 4th semester series (krishna).pdf
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
GUIDELINES ON SIMILAR BIOLOGICS Regulatory Requirements for Marketing Authori...
 
Animal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptxAnimal Communication- Auditory and Visual.pptx
Animal Communication- Auditory and Visual.pptx
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Creating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening DesignsCreating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening Designs
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 

Getting more out of Matplotlib with GR

  • 1. Getting more out of Matplotlib with GR July 20th – 26th, 2015 Bilbao | EuroPython 2015 | Josef Heinen | @josef_heinen MemberoftheHelmholtzAssociation
  • 2. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems ✓ visualize and analyzing two- and three-dimensional data sets ✓ plot 2D data for real-time monitoring purposes (signal processing) ✓ visualize large data sets, probably with a dynamic component, preferably in real-time  ✓ create publication-quality and web-ready graphics ✓ create animations or videos on the fly 2 Visualization needs
  • 3. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Python visualization solutions Matplotlib — de-facto standard (“workhorse”)
 ➟ Browser solutions: Bokeh, plot.ly Mayavi (mlab) — powerful, but overhead fromVTK ggplot, chaco — statistical, 2D graphics VTK — versatile, but difficult to learn Vispy, Glumpy, OpenGL — fast, but low-level API 3 2D 3D Bokeh Plotly ggplot chaco
  • 4. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems separated 2D and (hardware accelerated) 3D world some graphics backends "only" produce "figures"
 ➟ no presentation of continuous data streams speed up “only” by means of backend specific
 code ➟ poor performance on large data sets Problems so far — Crux of the matter 4 Quality Interop Speed
  • 5. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems How can we improve the performance? ✓ Several Python modules can be compiled into native code, making them much faster (Cython) ✓ Compiling hotspots on the fly (Numba, PyPy) can significantly speed up numerical code segments ✓ Use hardware acceleration, but … … these approaches cannot easily be applied to visualization software!
 ➟ Could another backend speedup Matplotlib and improve interop ? 5 Where to go from here?
  • 6. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Use GR to achieve more graphics performance ✓ procedural graphics backend (completely written in C)
 ➟ presentation of continuous data streams ✓ builtin support for 2D plotting and OpenGL (GR3)
 ➟ coexistent 2D and 3D world ✓ interoperability with GUI toolkits and Web frameworks
 ➟ good user interaction 6
  • 7. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Use GR to extend Matplotlib’s capabilities ✓ combine the power of Matplotlib and GR
 ➟ next Matplotlib release will allow selecting the backend by setting the environment variable MPLBACKEND ✓ produce video contents on the fly by adding a single line of code
 ➟ no need to import an animation module or write extra code ✓ create plots containing both 2D and 3D graphics elements 7
  • 8. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems How it works: GR layer architecture GKS logical device drivers C / C++ GKS GR OpenGL (WGL / CGL / GLX) POV-Ray
 generation off-screen rendering direct rendering Browser JavaScript
 generation WebGL IPython Win32X11 GKSTermgksqt LATEX Qt Quartz PDF C / ObjC OpenGL ES glgr / iGR App socket
 communication Qt / wx
 event loop 0MQ OpenGL More logical device drivers / plugins: – CGM, GKSM, GIF, RF, UIL – WMF, Xfig – GS (BMP, JPEG, PNG,TIFF) ... HTML5 wx POV-Ray GLUT GLFW wxGLCanvas QGLWidget ... SVGPS MOV GR3 Highlights: – simultaneous output to multiple output devices – direct generation of MPEG4 image sequences – flicker-free display ("double buffering”) – IPython / Jupyter notebook integration TikZ Swift PyPy Generate ray-traced graphics scenes Notebooks support for Python or Julia kernels Use GR as a Matplotlib backend;
 mix GR, MPL and GR3 code Create HTML5 output Qt console interaction Create video animations on the fly
  • 9. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Matplotlib using the GR backend 9 Circle Rectangle Wedge Polygon Ellipse Arrow PathPatch FancyBoxPatch Line2D ! % # % & ( * $# + ! % # % & ( * $# $% $& $( - #"# %"' '"# )"' $#"# $%"' $'"# $)"' %#"# %%"' +, ' %! $! #! "! ! "! #! $! %! ( %! $! #! "! ! "! #! $! %! ) "!! &! ! &! "!! # '$% # &$* # &$% # %$* %$% %$* &$% &$* '$% # '$% # &$* # &$% # %$* %$% %$* &$% &$* '$% 051..-7- 7/67 !'%% 431276" # %$(+ # %$') # %$&' %$%% %$&' %$') %$(+ %$), $"# $"( %"# %"( &"# &"( '"# '"( ("# $"# $"( %"# %"( &"# &"( '"# '"( ("# 4+30351,6. :/7. 0,9,06 ! #"* ! #") ! #"& #"# #"& #") #"* $"% $"( %"# %"( &"# &"( '"# '"( $"( %"# %"( &"# &"( '"# '"( +327385- :/7. 0,9,06 ! #"* ! #") ! #"& #"# #"& #") #"* $"% 0° 45° 90° 135° 180° 225° 270° 315° 2 4 6 8 10 ( & $ " $ & ( ( & $ " $ & ( #!"# "!)+ "!'( "!%& "!## "!## "!%& "!'( "!)+ #!"# "!* "!( "!& "!$ "!" "!$ "!& "!( "!* # &$% # %$' %$% %$' &$% # &$% # %$' %$% %$' &$% )/07,5/2- * (,0*82*9 1,6. !*440/+*7/32 73 ./-.# 5,63087/32 75/+327385/2-" #!" "!& "!" "!& #!" #!" "!& "!" "!& #!" "!' "!% "!$ "!" "!$ "!% "!'
  • 10. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems GR in action … 10
  • 11. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems GR / Jupyter Performance (anim.py) 0 100 200 300 400 500 600 700 MPL MPL+GR GR fps click images to view notebooks …
  • 12. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Performance analysis 0 100 200 300 400 500 600 700 MPL MPL+GR GR fps ncalls cumtime filename:lineno(function) 398 6.852 {method'draw'of'_macosx.FigureCanvas'objects} 29378/397 6.771 artist.py:57(draw_wrapper) 397 6.769 figure.py:1004(draw) 397 6.574 _base.py:1989(draw) 794 5.894 axis.py:1106(draw) 5161 4.601 axis.py:232(draw) 199 3.616 pyplot.py:175(pause) 10719 3.609 lines.py:661(draw) 199 3.480 pyplot.py:551(draw) 7940 1.044 text.py:581(draw) ncalls cumtime filename:lineno(function) 199 4.412 pyplot.py:551(draw) 199 4.410 backend_gr.py:227(draw) 14726/199 4.237 artist.py:57(draw_wrapper) 199 4.236 figure.py:1004(draw) 199 4.138 _base.py:1989(draw) 398 3.770 axis.py:1106(draw) 2587 3.073 axis.py:232(draw) 5373 2.642 lines.py:661(draw) 5174 1.202 backend_bases.py:237(draw_markers) ncalls cumtime filename:lineno(function) 199 3.263 __init__.py:1910(plot) 199 3.184 __init__.py:250(updatews) MPL MPL + GR GR most time spent in backend wrapper ??? No room for further optimizations on the backend side
  • 13. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems GR + GR3 + Matplotlib interop 13 Matplotlib GR3 GR Important: tells MPL backend not to update
  • 14. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Inline graphics Matplotlib GR ~ 10 times faster
  • 15. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Demos ✓ Animated graphics performance comparison: Matplotlib vs. GR (anim.ipynb) ✓ GR / mogli / Matplotlib interoperability example (interop.ipynb) ✓ Inline graphics performance comparison: Matplotlib vs. GR (inline.ipynb) ✓ Simple spectral (specgram.ipynb)
  • 16. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems GR + GKS can be transpiled to JS
 (Emscripten: LLVM-to-JavaScript compiler) 
 ➟ Use cases: ✓ embed JS code in IP[y]: or IJulia (Jypyter) ✓ parse GKS JavaScript logical device driver
 generated display list in browser Outlook (GR release v0.15.0) JavaScript
  • 17. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems What else can GR be used for? pyMolDyn see Poster session: Embedding visualization applications with pygr by Christian Felder
  • 18. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Conclusions ✓ Using the GR Matplotlib backend has not turned out satisfactory as the speedups were not as expected ✓ GR adds more plotting capabilities to Matplotlib allowing to mix 2D drawings and 3D graphics scenes or create movies on the fly ✓ Producing plots / figures is much faster with the GR framework (speedup for plots > 20, > 100 respectively) 18
  • 19. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems What happens next? ✓ integrate JavaScript GKS logical device driver ✓ provide more convenience function ✓ migrate the GR3 library to modern OpenGL (using OpenGL shader language)
 ➟ visualize millions of vertices / faces ✓ simplify the installation 19
  • 20. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Resources ✓ Website: http://gr-framework.org ✓ GR framework: https://github.com/jheinen/gr ✓ PyPI: https://pypi.python.org/pypi/gr ✓ Talk material: Getting more out of Matplotlib with GR 20
  • 21. July 20th – 26th, 2015 Josef Heinen, Forschungszentrum Jülich, Peter Grünberg Institute, Scientific IT Systems Thank you for your attention Questions? Contact: j.heinen@fz-juelich.de
 @josef_heinen Thanks to: Fabian Beule, Steffen Drossard, Christian Felder, Marvin Goblet, Ingo Heimbach, Daniel Kaiser, Philip Klinkhammer, David Knodt, Florian Rhiem, Jörg Winkler et al. 21