Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.
description
Transcript of Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.
![Page 1: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/1.jpg)
Matplotlib:from brain surgery to rocket scienceJohn D. Hunter, Ph.D.Perry Greenfield, Ph.D.
http://matplotlib.sourceforge.net
![Page 2: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/2.jpg)
brain surgery…
![Page 3: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/3.jpg)
dongle
![Page 4: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/4.jpg)
pbrain
![Page 5: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/5.jpg)
loc3djr
http://pbrain.sourceforge.net
![Page 6: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/6.jpg)
The three stages of python• Matlab hell• Python purgatory• The path to
enlightenment
![Page 7: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/7.jpg)
3D python fantastic, but 2D?PyX, ChartDirector, biggles, DISLIN, gnuplot, chaco, xplt, gplt, pyngl, ppgplot, tkinter canvas, gtk-extras, pychart, gist, piddle, graphite….
• Multiple plotting idioms
• Cross platform
• Publication quality
• Permissive license
• Extensible (by me!)
• Easy plots should be easy (OO not always best)
• But app embedding should be supported (OO sometimes best)
• GUI agnosticism
• The curse of python
![Page 8: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/8.jpg)
# matplotlib 0.1~/python/matplot_gtk12> lsREADME matplotlib.py subplot_demo.pydata simple_plot.py view_data.pymatplot.py stock_demo.py vline_demo.py
# matplotlib 0.73
53 python modules
17 files of extension code
44,000 lines of code
130 examples
• 2-5 active developers at any time; 25 contributors
•Co-developed with NASA STScI and JPL
• 1200-1500 downloads/month
• approx 10 messages per/day on mailing list
![Page 9: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/9.jpg)
Copy the great architecturesE Tufte
![Page 10: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/10.jpg)
backends
![Page 11: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/11.jpg)
The matplotlib APIfrom matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvasfrom matplotlib.figure import Figure
fig = Figure()canvas = FigureCanvas(fig)ax = fig.add_subplot(111)ax.plot([1,2,3]) aax.set_title('hi mom')ax.grid(True)ax.set_xlabel('time')ax.set_ylabel('volts')fig.savefig('test')
![Page 12: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/12.jpg)
pylab interface
• Plotting should just work
• Easy plots should be easy
• GUI / interactive complexity should be managed
• ipython to the rescue
IPython 0.6.12_cvs -- An enhanced Interactive Python.? -> Introduction to IPython's features.%magic -> Information about IPython's 'magic' % functions.help -> Python's own help system.object? -> Details about 'object'. ?object also works, ?? prints more.
Welcome to pylab, a matplotlib-based Python environment help(matplotlib) -> generic matplotlib information help(pylab) -> matlab-compatible commands from matplotlib help(plotting) -> plotting commands
In [1]: plot([1,2,3])
![Page 13: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/13.jpg)
# Numericfrom Numeric import array, wherefrom MLab import stdfrom Numeric import convolvefrom FFT import fft
# numarrayfrom numarray import array, wherefrom numarray.linear_algebra.mlab import stdfrom numarray.convolve import convolvefrom numarray.fft import fft
# matplotlib.numerixfrom matplotlib.numerix import array, wherefrom matplotlib.numerix.mlab import, mean, std
# choose numeric or numarray from the shellC:> python myscript.py --numarray
# or in an rc file settingnumerix : ‘numarray’
The numerix module
![Page 14: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/14.jpg)
font manager
• Cross platform font finding: win32, linux, OS X
• Configurable families: the font engine will pick the best font to match your requirements
• W3C compliant
font.family : sans-seriffont.style : normalfont.variant : normalfont.weight : mediumfont.stretch : normalfont.size : mediumfont.serif : New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Bitstream Vera Serif, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, seriffont.sans-serif : Lucida Grande, Verdana, Geneva, Lucida,
![Page 15: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/15.jpg)
tex = r'$\cal{R}\prod_{i=\alpha_{i+1}}^\infty a_I … \rm{sin}(2 \pi f x_i)$'text(1, 1.6, tex, fontsize=30)
mathtext demo
![Page 16: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/16.jpg)
bar demo
![Page 17: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/17.jpg)
stacked bar
![Page 18: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/18.jpg)
pie demo
![Page 19: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/19.jpg)
scatter demo
![Page 20: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/20.jpg)
histogram demo
![Page 21: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/21.jpg)
log demo
![Page 22: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/22.jpg)
polar demo
![Page 23: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/23.jpg)
layer image
![Page 24: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/24.jpg)
subplot demo
![Page 25: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/25.jpg)
axes demo
![Page 26: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/26.jpg)
legend demo
![Page 27: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/27.jpg)
text alignment
![Page 28: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/28.jpg)
mathtext demo2
![Page 29: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/29.jpg)
cylindrical equidistant, mercator, lambert conformal conic, lambert azimuthal equal area, albers equal area conic and stereographic.
basemaptoolkit
![Page 30: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/30.jpg)
stock demo
![Page 31: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/31.jpg)
finance demo
![Page 32: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/32.jpg)
MRI with eeg
![Page 33: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/33.jpg)
EEG demo
![Page 34: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/34.jpg)
VTK demo
![Page 35: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/35.jpg)
Did I talk about?
• Event handling
• set/set Introspection
• RC configuration
• Embedding
• Dynamic/animated plots
• Math text
• Contouring
• Toolkits / basemap
• Font management
![Page 36: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/36.jpg)
…from astronomy to zoology?• Basic 3D• Different colorspaces (CMYK)• Arbitrary clipping paths, gradient/pattern fills• Unicode support & better TeX support• Domain specific toolkits• SWF, PDF, Aqua, …• Direction fields, arrows, etc
![Page 37: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/37.jpg)
MATPLOTLIB CREDITS (in order of appearance…)
• Jeremy O'Donoghue wrote the wx backend• Andrew Straw provided much of the log scaling architecture, the fill command, PIL support for
imshow, and provided many examples• Charles Twardy provided the impetus code for the legend class and has made countless bug
reports and suggestions for improvement.• Gary Ruben made many enhancements to errorbar to support x and y errorbar plots, and added a
number of new marker types to plot.• John Gill wrote the table class and examples• David Moore wrote the paint backend• Todd Miller contributed the TkAgg backend and the numerix module, which allows matplotlib to
work with either numeric or numarray. He also ported image support to the postscript backend, with much pain and suffering.
• Paul Barrett overhauled font management to provide an improved, free-standing, platform independent font manager with a WC3 compliant font finder and cache mechanism and ported truetype and mathtext to PS
• Perry Greenfield overhauled and modernized the goals and priorities page, implemented an improved colormap framework, and has provided many suggestions and a lot of insight to the overall design and organization of matplotlib.
• Jared Wahlstrand wrote the SVG backend
![Page 38: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/38.jpg)
MATPLOTLIB CREDITS (continued)
• Steve Chaplin is the GTK maintainer and wrote the Cairo and GTKCairo backends• Jim Benson provided the patch to handle vertical mathttext• Gregory Lielens provided the FltkAgg backend and several patches for the frontend, including
contributions to toolbar2, and support for log ticking with alternate bases and major and minor log ticking
• Darren Dale did the work to do mathtext exponential labeling for log plots.• Paul Mcguire provided the pyparsing module on which mathtext relies, and made a number of
optimizations to the matplotlib mathtext grammar.• Fernando Perez has provided numerous bug reports and patches for cleaning up backend
imports and expanding pylab functionality, and provided matplotlib support in the pylab mode for ipython. He also provided the matshow command.
• Andrew Dalke of Dalke Scientific Software contributed the strftime formatting code to handle years earlier than 1900
• Jochen Voss maintained the PS backend and has contributed several bugfixes.• Nadia Dencheva of STScI provided the contouring and contour labeling code• Baptiste Carvello provided the key ideas in a patch for proper shared axes support that underlies
ganged plots and multiscale plots• Sigve Tjoraand Ted Drain and colleagues at the JPL collaborated on the QtAgg backend• Eric Firing added the contourf function and general contour refactoring
![Page 39: Matplotlib: from brain surgery to rocket science John D. Hunter, Ph.D. Perry Greenfield, Ph.D.](https://reader035.fdocuments.us/reader035/viewer/2022070410/56814669550346895db38d1a/html5/thumbnails/39.jpg)
pie demo