Advanced PairGrid Visualization of Tips Dataset

Load the ‘tips’ dataset. Create a PairGrid which shows a histogram on the diagonal, a scatter plot on the upper triangle, and a kde plot on the lower triangle.

Example Output:

Create a sns.PairGrid, then use the map_diag, map_upper, and map_lower functions.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import seaborn as sns
import matplotlib.pyplot as plt
def plot_complex_pairgrid():
tips_data = sns.load_dataset('tips')
g = sns.PairGrid(tips_data)
g.map_diag(plt.hist)
g.map_upper(plt.scatter)
g.map_lower(sns.kdeplot)
plt.show()
plot_complex_pairgrid()
import seaborn as sns import matplotlib.pyplot as plt def plot_complex_pairgrid(): tips_data = sns.load_dataset('tips') g = sns.PairGrid(tips_data) g.map_diag(plt.hist) g.map_upper(plt.scatter) g.map_lower(sns.kdeplot) plt.show() plot_complex_pairgrid()
import seaborn as sns
import matplotlib.pyplot as plt

def plot_complex_pairgrid():
    tips_data = sns.load_dataset('tips')
    g = sns.PairGrid(tips_data)
    g.map_diag(plt.hist)
    g.map_upper(plt.scatter)
    g.map_lower(sns.kdeplot)
    plt.show()

plot_complex_pairgrid()

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!