Day (5) — Data Visualization — How to use Seaborn Grids

Keith Brooks
4 min readMar 4, 2018

--

“A red neon sign reads "SPAGHETTI" on a wall of a restaurant seen through the window.” by Ben Neale on Unsplash

This article covers work from the Python for Data Science and Machine Learning Bootcamp course on Udemy by Jose Portilla and helpful tips along the way. This course was very helpful in gaining a base understanding of the topic.

When cooking a recipe, it is good to go by the base instructions. I learned that when I had to cook my meals in undergrad. I would find great recipes and begin to prepare by the book. But, the day came when I wanted a little something different. I wanted to customize it just a bit…Well, that is kind of how Seaborn Grids work. Or at least how I feel it works. They allow for more customization of the previous .pairplots() method, which is very helpful for quick data visualizations.

Topics:
* How to use PairGrid to generate customized two dimensional plots
* How to use FacetGrid to generate customized plots with three arguments

The Setup:
* The example uses Python 3.6 within Jupyter notebook with the below dependencies
Matplotlib 2.1.2
Numpy 1.14.1
Seaboard 0.7.1

Warning:
* Feel free to review the docs for additional arguments for the methods.

PairGrid
The .pairplot() method may be thought of as a simplified version of the PairGrid. The .pairplot() method provides a cookie cutter approach to plot selection.

The PairGrid does require further setup, but it also provides greater control of the output. This comes in the form of specifying the plots to be used in relation to the grid. It feels good when the best plot form can be used for the data relation in question. Below is the process.

Step (1)
— Use the .PairGrid method to create a grid with empty plots for the numerical columns for the dataset.

Step (2)
- Use the .map() method to define the specific plot types that are to be used. The .map_diag(), .map_upper(), and .map_lower() methods specify the locations of the plots for the custom grid. Below we use the seaborn distribution plots on the diagonal, the matplotlib scatter plot in the upper right corner and the seaborn kernel distribution plot in the lower left.

FacetGrid
However, if feeling froggy then the FacetGrid may be another option. This method takes three arguments referring to elements from the dataset to represent rows, columns and values. Feel free to use the .info() method to recall the columns again from the dataset.

dataset_name.info()

If familiar with Excel, this is similar to the inputs of a pivot table. Below is the process…

Step (1)
- Use the .FacetGrid() method we arguments for data, col and row.

Step (2)
- Use the .map() method to apply function to loop over data to generate the custom plot.

But wait, there is more…If there is further information to dissect, the .map() method allows us to input more for even greater details.

Step (3)
- Further dissect the plot with providing additional arguments to the .map() method. Below we have tips on the y axis, total_bill variable on the x axis and we split the plots up in each quandrant by smoker and lunch/dinner time. This really allows for a richer visual story.

Well, time to say goodbye to shane.

“Wealth consists not in having great possessions, but in having few wants.” ~ Epictetus

--

--

Keith Brooks

Hi…This is intended to document my journey on my path to data science. I am a process oriented individual who loves to try new things and continue to learn.