Other Tools for Visualization

11.7. Other Tools for Visualization

There are many software packages and tools for creating data visualizations. In this book, we primarily use plotly. But it’s worth knowing about a few other commonly used tools. In this section, we’ll compare plotly to matplotlib and grammar of graphics tools.

11.7.1. matplotlib

matplotlib is one of the first data visualization tools for Python. Because of this, it is widely used and has a large ecosystem of packages. Notably, the built-in plotting methods for pandas dataframes make plots using matplotlib. One popular package that builds on top of matplotlib is called seaborn. Compared to matplotlib alone, seaborn provides a much simpler API to create statistical plots, like dot plots with confidence intervals. In fact, seaborn’s API was used as an inspiration for plotly’s API. If you look at plotly code and seaborn code side-by-side, you’ll find that creating basic plots methods uses similar code.

One advantage of using matplotlib is its popularity. It’s relatively easy to find help creating or fine-tuning plots online because many existing projects use it. For this book, the main advantage of using plotly is that the plots we create are interactive. Plots in matplotlib are usually static images, which don’t allow for panning, zooming, or hovering over marks. Still, we expect that matplotlib will continue to be used for data analyses, so we think it’s worth learning the basics by looking through its documentation 1.

11.7.2. Grammar of Graphics

The grammar of graphics is a mathematical theory for creating data visualizations [Wilkinson, 2012]. The basic idea is to find common building blocks for making plots. For instance, a bar plot and a dot plot are nearly identical, except that a bar plot draws rectangular marks and a dot plot draws points. This idea is captured in the grammar of graphics, which would say that a bar plot and a dot plot differ only in their “geometry” component. The grammar of graphics is an elegant system since we can use it to derive nearly every kind of plot we wish to make.

This system is implemented in the popular plotting libraries ggplot2 for the R programming language and vega for JavaScript. A Python package called altair provides a way to create vega plots using Python, and we encourage interested readers to look over its documentation 2.

Using a grammar of graphics tool like altair enables great flexibility in visualizations. And like plotly, altair also creates interactive visualizations. However, the Python API for these tools can be less straightforward than plotly’s API. In this book, we don’t typically need plots outside of what plotly is capable of creating, so we opted for plotly’s simpler API.

There are many more plotting tools for Python that we’ve left out for brevity. But for the purposes of this book, relying on plotly provides a useful balance of interactivity and flexibility. In the next section, we’ll summarize what we’ve covered in this chapter.