Sidebar: The challenge of writing a good plotting language

A naked sine curve is a single visual concept, but it takes hundreds of points to represent smoothly. Because humans are so damn good at interpreting their visual world, plots look simpler than they are. If you add in axes, labels, a grid, and linestyles in all their variations, even a simple plot becomes quite complicated to represent.

There are two solutions to this. The first is to provide preselected option groups for common patterns. Bundling these provides a much simpler user interface. The user gives up control but gets ease of use and a very concise language in return.

The other extreme is to build a very expressive plot building language. Expose every option to the user. The user retains full control over every aspect of the plot, but may have to write many more lines of code and do a lot more googling to get there.

Matplotlib does an excellent job straddling this trade off. There are quick ways to create common plot types. These are part of its scripting interface, designed specifically to be lightweight and for interactive use. 

Matplotlib also lets users dig as deeply as they want into its full object oriented code, using the low-level code to modify every aspect of the plot.

A common path is to start using the scripting interface, and then when you want to modify something outside the preselected options, finding the object oriented method for doing it on StackOverflow or the marvelous Matplotlib docs. Over time as you assert more control, you migrate toward the low-level interface.

Some third party libraries, like Seaborn and Altair, have helped to procrastinate this transition by making especially attractive default designs for common analysis types. They illustrate another great strategy in this trade off: have a low-level interface available, but also have a carefully selected set of default options. This let you get 90% of the way there on the first try. And most of the time, 90% is enough.

This has been thrown into sharp relief for me lately while writing this course. The trade-off between expressive power and complexity of a language. It’s a recurring theme, but nothing makes it relevant like making pictures.

For a delightful and detailed head-to-head comparison of Matpoltlib, Seaborn, Altair and others, read this. Perhaps with a glass of wine.