matplotlib: up and running (pycon canada 2015)

21

Upload: christopher-roach

Post on 10-Feb-2017

462 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Matplotlib: Up and Running (PyCon Canada 2015)

UP AND RUNNINGMATPLOTLIB

Page 2: Matplotlib: Up and Running (PyCon Canada 2015)

Hi

Page 3: Matplotlib: Up and Running (PyCon Canada 2015)

OUTLINE

▸ Understanding matplotlib

▸ History of matplotlib

▸ The Anatomy of maptlotlib

▸ The Interfaces of matplotlib

▸ Overview of the pyplot interface

▸ Uses for matplotlib

Page 4: Matplotlib: Up and Running (PyCon Canada 2015)

HISTORYMATPLOTLIB

Page 5: Matplotlib: Up and Running (PyCon Canada 2015)

JOHN HUNTER (1968 - 2012)

Page 6: Matplotlib: Up and Running (PyCon Canada 2015)

THE DONGLE PROBLEM

Page 7: Matplotlib: Up and Running (PyCon Canada 2015)

MATPLOTLIB (1.0)

▸ Was meant to be an alternative to MATLAB

▸ Created by John Hunter for examining data from epileptic patients

Page 8: Matplotlib: Up and Running (PyCon Canada 2015)

MATPLOTLIBTHE ANATOMY OF

Page 9: Matplotlib: Up and Running (PyCon Canada 2015)

ANATOMY OF A GRAPHIC

▸ The Figure contains and manages all elements in a graphic

▸ Key architectural decision was to separate the Figure from the act of rendering

Page 10: Matplotlib: Up and Running (PyCon Canada 2015)

THREE DISTINCT LAYERS

▸ Scripting Layer (pyplot)

▸ Artist Layer

▸ Everything in a graphic is an Artist

▸ Knows how to “draw” itself

▸ Backend Layer

▸ Presents a generic drawing interface (e.g., draw_point, draw_line, etc.)

▸ Interacts with the “physical” world

BACKEND LAYER

SCRIPTING LAYER

ARTIST LAYER

Page 11: Matplotlib: Up and Running (PyCon Canada 2015)

THE INTERFACESMATPLOTLIB

Page 12: Matplotlib: Up and Running (PyCon Canada 2015)

THREE INTERFACES OF MATPLOTLIB

▸ pylab (deprecated)

▸ pyplot

▸ The Object-Oriented API

Page 13: Matplotlib: Up and Running (PyCon Canada 2015)

PYLAB

▸ Pros

▸ Least verbose

▸ Cons

▸ Imports everything into global space

▸ When?

▸ It’s deprecated

▸ Ok, fine, one-off, “throwaway” code only!

Page 14: Matplotlib: Up and Running (PyCon Canada 2015)

PYPLOT

▸ Pros

▸ Namespaces!

▸ Cons

▸ Less control

▸ When?

▸ Interactive data exploration

▸ Small batch visualizations

Page 15: Matplotlib: Up and Running (PyCon Canada 2015)

THE OBJECT-ORIENTED API

▸ Pros

▸ Total control

▸ Cons

▸ Syntactically heavy

▸ When?

▸ Embedding

▸ Large batch visualizations

Page 16: Matplotlib: Up and Running (PyCon Canada 2015)

THE SCRIPTING INTERFACEMATPLOTLIB

Page 17: Matplotlib: Up and Running (PyCon Canada 2015)

PYLOT

▸ MATLAB-like

▸ procedural

▸ stateful

Page 18: Matplotlib: Up and Running (PyCon Canada 2015)

STATEFUL INTERFACE

plt.plot(x, y) plt.gca() plt.gcf()

FIGURE 1

FIGURE 2

FIGURE 3

FIGURE 3

fig.clf()

Page 19: Matplotlib: Up and Running (PyCon Canada 2015)

DEMO TIME

Page 20: Matplotlib: Up and Running (PyCon Canada 2015)

MATPLOTLIB 1.5.0 IS OUT -- STILL ALIVE AN[D] KICKING WITH PANDAS DATAFRAME SUPPORT AND PRETTY SEABORN STYLES

rasbt - r/Python

Page 21: Matplotlib: Up and Running (PyCon Canada 2015)

THE FUTURE

▸ Modern Libraries

▸ Seaborn

▸ ggplot

▸ mpld3 and bokeh (for the web)

▸ Spyre

▸ New (and Custom) styles