Module 6 · Seaborn · Lesson 33 of 66

Grids

Repeat a chart for every pair of columns or every group with PairGrid, FacetGrid and JointGrid.

In this lesson · about 12 minutes

  • Control each part of a pair plot with PairGrid
  • Draw one chart per group with FacetGrid
  • Build a custom joint plot with JointGrid

Grids are the machinery behind pairplot, catplot and jointplot. Using them yourself lets you choose exactly which chart goes in each spot. The pattern is always the same: make the grid, then .map a plotting function onto it.

PairGrid

sns.PairGrid(df) makes an empty grid with one cell per pair of number columns. Map one chart to the diagonal and others to the upper and lower triangles.

FacetGrid

sns.FacetGrid(data, col='a', row='b') makes one panel for every combination of the values in those columns. g.map(plt.hist, 'total_bill') then draws a histogram of total_bill in each panel, using only that panel's rows. Charts that need two columns take both: g.map(plt.scatter, 'total_bill', 'tip').

Exercise

A histogram per group

Make a FacetGrid of tips with a column for each time and a row for each smoker value, and draw a histogram of total_bill in every panel.

Code that runs before yours
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset('tips')

JointGrid

sns.JointGrid is the frame of a joint plot. plot(main, edges) picks the chart for the middle and the one for the two edges.

Exercises solved: 0 of 1

Tip: solve each exercise first. Press Check to test your code.

Noviq Academy's Data Science course is free and for learning. Python runs in your browser with Pyodide, which downloads about 20 MB the first time, plus a few more for scikit-learn. Your code and progress stay on this device. The salaries data is a sample of San Francisco's public pay records; the purchases, customers, housing, advertising and classified data are made up. The Titanic, tips, flights and iris data sets come from Seaborn's examples; the maps use public 2011 to 2014 US and world figures. The 911 data is a 20,000-call sample of Montgomery County, Pennsylvania's public 911 records; the movie ratings are the MovieLens 100K data from GroupLens Research; the reviews are a 3,000-review sample from the Yelp Dataset Challenge; the loans are public LendingClub data; the colleges are the College data from An Introduction to Statistical Learning; the bank notes, kyphosis and breast cancer data come from the UCI Machine Learning Repository. Spark and TensorFlow can't run in a browser, so those lessons use stand-ins that run here, and show the code for the real tools.