introduction to plotting in python

22
Bohumír Zámečník @bzamecnik Introduction to plotting in Python for Data Science Workshop 2016-01-07

Upload: bzamecnik

Post on 20-Jan-2017

463 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Introduction to plotting in Python

Bohumír Zámečník@bzamecnik

Introduction toplotting in

Python for Data Science Workshop

2016-01-07

Page 2: Introduction to plotting in Python

Agenda● mostly how to plot with

● practical examples● tips for other packages

http://matplotlib.org/basemap/users/examples.html

Page 3: Introduction to plotting in Python

Why plotting in Python?● GUI is not practical for complex plots● "no more Excel headache"● code can be automatized easily● nice integrates with data processing● Python is full language (sorry MATLAB)● coding in Python is fun

Page 4: Introduction to plotting in Python

● Python package● for 2D plotting● publication quality● & interactive plots● very powerful● very popular● many extensions

http://stanford.edu/~mwaskom/software/seaborn/examples/hexbin_marginals.html

What is ?

Page 5: Introduction to plotting in Python

History & motivation

● since 2002 (~14 years)● needed to plot

brain activity (EEG)● MATLAB was

not powerful enough

John Hunter (1968-2012)

http://matplotlib.org/users/screenshots.html

Page 6: Introduction to plotting in Python

The basic workflow

1. specify plot asPython code

2. output to PNG, PDF,GUI, Jupyter, etc.

Page 7: Introduction to plotting in Python

Hello, world!in matplotlib

Motto:"Make easy things easyand hard things possible."

Page 8: Introduction to plotting in Python

Architecture● scripting layer● artist layer● backend layer

from book:Mastering matplotlib

by Duncan M. McGreggorPackt Publishing, 2015

Page 9: Introduction to plotting in Python

Scripting layer● pyplot

○ syntax sugar○ stateful API○ high-level object API○ you typically use this

● pylab○ compatibility with MATLAB○ deprecated

Page 10: Introduction to plotting in Python

Artist layer● what should be rendered?● parts of the plot● object-oriented API● primitives - Line2D, Rectangle, Text, Image● containers

○ Figure - full plot○ Axes - single subplot○ Axis - one axis

Page 11: Introduction to plotting in Python

Backend layer● how it should be rendered?● interactive

○ Tk, GTK, Qt, OS X, WX● hardcopy

○ raster – AGG, GDK, NBAGG, Cairo○ vector – PS, PDF, SVG, Cairo

● FigureCanvas - area where Figure is drawn● Renderer - knows how to draw

Page 13: Introduction to plotting in Python

Practical examplesin a Jupyter notebook

https://gist.github.com/bzamecnik/b58579e319287abcb3ca

Page 14: Introduction to plotting in Python

Extensions & other packages

seaborn

ggplot

plot.ly

bokeh

Page 15: Introduction to plotting in Python

matplotlib drawbacks● quite old● too focused on server-side● too cross-platform● not awesomely beautiful by default

Page 16: Introduction to plotting in Python

Seaborn: statistical data visualization● matplotlib extension● beautiful theme● statistical plots

○ distribution■ hexbin, violin plot, etc.

○ scatterplot○ pairwise correlations

http://stanford.edu/~mwaskom/software/seaborn/examples/grouped_violinplots.html

Page 17: Introduction to plotting in Python

ggplot from ŷhat

● based on○ Grammar of Graphics○ ggplot2 from R

http://ggplot.yhathq.com/

Page 18: Introduction to plotting in Python

Bokeh● based on D3.js● client-side● interactive

● beautiful● high-performance

http://bokeh.pydata.org/

Page 19: Introduction to plotting in Python

Plot.ly● cloud service● can publish plots● free for public plots● API & Python library● interactive, beautiful● good for dashboards

https://plot.ly/python/choropleth-maps/

Page 20: Introduction to plotting in Python

Summary● plotting in Python is nice & powerful● sometimes a bit overwhelming● it is worth learning it!

Wish you nice plots!

Page 21: Introduction to plotting in Python

http://audioml.clubA little ad :)

Page 22: Introduction to plotting in Python

Thanks!Q&A

Bohumír Zámečník@bzamecnik Python Workshop

Intro to Plotting in Python