With the availability of powerful but relatively low-level plotting libraries like d3.js, plot.ly, and matplotlib, it is easier than it has ever been to create beautiful visualizations. However, these plotting libraries must be very general and thus quite complicated to accommodate arbitrarily complex plotting and visualization tasks.In this talk, I describe the plotting system used by yt, an analysis and visualization platform for volumetric data written in python. The yt plotting system wraps matplotlib, creating a domain-specific API for creating publication quality plots that matches users' intuition for how they would like to explore and visualize their data. I will provide tips for designing and testing domain-specific plotting APIs so that the resulting plots are beautiful by default, but still modifiable with the full power of the underlying plotting library.
3. Generic Plotting Libraries are Powerful
John Hunter Plotting Contest Entries: http://scipy2016.scipy.org/ehome/115969/276538/
4. Creative Power Implies API Complexity
4
I’m picking on matplotlib here, but the
same is true of any generic plotting library
5. 5
● Declarative Visualization
Libraries
○ Vega-lite, ggplot, altair
● Documentation by example
○ Users create plots by
cargo-culting examples
● Provide shortcuts in high-level
API
○ “Easy mode” can’t cover all
use cases
Managing API Complexity
6. 6
Alternate approach: make assumptions for users
APLpy
Astronomical Data
https://aplpy.github.io
Cartopy
Geographic Data
http://scitools.org.uk/cartopy/
7. yt: 3D Data Analysis
7
Ingest Data
Analysis/
Visualization
yt-project.org
Ramses
Gadget
15. 15
yt: A Community of Practice
>100 Contributors as of yt 3.3.2 (Oct 2016)
Tom Abel Bili Dong Suoqing Ji Sam Leitner John Regan Geoffrey So
Gabriel Altay Nicholas Earl Allyson Julian Yuan Li Mark Richardson Casey W. Stark
Kenza Arraki Hilary Egan Christian Karch Alex Lindsay Sherwood Richers Antoine Strugarek
Kirk Barrow Daniel Fenn Max Katz Chris Malone Thomas Robitaille Elizabeth Tasker
Ricarda Beckmann John Forbes BW Keller Jonah Miller Anna Rosen Ben Thompson
Elliott Biondo Enrico Garaldi Ji-hoon Kim Joshua Moloney Chuck Rozhon Robert Thompson
Alex Bogert Sam Geen Chang-Goo Kim Christopher Moody Douglas Rudd Joseph Tomlinson
Robert Bradshaw Austin Gilbert Steffen Klemer Stuart Mumford Hsi-Yu Schive Stephanie Tonnesen
Andre Bubel Adam Ginsburg Fabian Koller Andrew Myers Anthony Scopatz Matt Turk
Corentin Cadiou Nathan Goldbaum Kacper Kowalik Jill Naiman Noel Scudder Miguel de Val-Borro
Yi-Hao Chen William Gray Mark Krumholz Desika Narayanan Patrick Shriwise Rick Wagner
Pengfei Chen Markus Haider Michael Kuhlen Kaylea Nelson Devin Silvia Mike Warren
David Collins Eric Hallman Meagan Lang Brian O'Shea Sam Skillman Charlie Watson
Brian Crosby David Hannasch Erwin Lau J.S. Oishi Stephen Skory Andrew Wetzel
Weiguang Cui Cameron Hummels Eve Lee JC Passy Aaron Smith John Wise
Andrew Cunningham Anni Järvenpää Doris Lee Rafael Ruggiero Britton Smith Michael Zingale
“Scaling a code in the human dimension”: https://arxiv.org/abs/1301.7064
16. 16
yt: A Community of Practice
Tom Abel Bili Dong Suoqing Ji Sam Leitner John Regan Geoffrey So
Gabriel Altay Nicholas Earl Allyson Julian Yuan Li Mark Richardson Casey W. Stark
Kenza Arraki Hilary Egan Christian Karch Alex Lindsay Sherwood Richers Antoine Strugarek
Kirk Barrow Daniel Fenn Max Katz Chris Malone Thomas Robitaille Elizabeth Tasker
Ricarda Beckmann John Forbes BW Keller Jonah Miller Anna Rosen Ben Thompson
Elliott Biondo Enrico Garaldi Ji-hoon Kim Joshua Moloney Chuck Rozhon Robert Thompson
Alex Bogert Sam Geen Chang-Goo Kim Christopher Moody Douglas Rudd Joseph Tomlinson
Robert Bradshaw Austin Gilbert Steffen Klemer Stuart Mumford Hsi-Yu Schive Stephanie Tonnesen
Andre Bubel Adam Ginsburg Fabian Koller Andrew Myers Anthony Scopatz Matt Turk
Corentin Cadiou Nathan Goldbaum Kacper Kowalik Jill Naiman Noel Scudder Miguel de Val-Borro
Yi-Hao Chen William Gray Mark Krumholz Desika Narayanan Patrick Shriwise Rick Wagner
Pengfei Chen Markus Haider Michael Kuhlen Kaylea Nelson Devin Silvia Mike Warren
David Collins Eric Hallman Meagan Lang Brian O'Shea Sam Skillman Charlie Watson
Brian Crosby David Hannasch Erwin Lau J.S. Oishi Stephen Skory Andrew Wetzel
Weiguang Cui Cameron Hummels Eve Lee JC Passy Aaron Smith John Wise
Andrew Cunningham Anni Järvenpää Doris Lee Rafael Ruggiero Britton Smith Michael Zingale
>100 Contributors as of yt 3.3.2 (Oct 2016)
“Scaling a code in the human dimension”: https://arxiv.org/abs/1301.7064
30. import yt
import yt.units as u
ds = yt.load('DD0600/DD0600')
prj = yt.ProjectionPlot(
ds, 'z', 'density', width=15*u.kpc)
prj.save()
Short but powerful scripts
● Register namespace
● Set up unit metadata for further
use later
30
31. import yt
import yt.units as u
ds = yt.load('DD0600/DD0600')
prj = yt.ProjectionPlot(
ds, 'z', 'density', width=15*u.kpc)
prj.save()
Short but powerful scripts
● Automagically determine data
format
● Parse parameters
● Initialize IO and data selection
interface
31
32. import yt
import yt.units as u
ds = yt.load('DD0600/DD0600')
prj = yt.ProjectionPlot(
ds, 'z', 'density', width=15*u.kpc)
prj.save()
Short but powerful scripts
● Set up in-memory mesh
● Determine available fields to plot
● Chunked IO
● Mask out overlapping data
● Convert to data CGS units
● Perform projection
● Pixelize from multi-resolution
projection
● Initialize plot object
32
33. import yt
import yt.units as u
ds = yt.load('DD0600/DD0600')
prj = yt.ProjectionPlot(
ds, 'z', 'density', width=15*u.kpc)
prj.save()
Short but powerful scripts
● Calculate positioning and
metadata for matplotlib plot
● Create and customize matplotlib
Figure and Axes objects
● Call imshow() with appropriate
keyword arguments
● Save plot to disk
33
34. Generic plotting libraries can’t make assumptions
34
import matplotlib.pyplot as plt
plt.imshow(image_data)
plt.savefig('plot.png')
37. 37
Ingestion Representation Analysis Visualization
Community
Science
Build new libraries for your use cases
Add new plotting tasks to libraries that already exist