• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to Make Pairplot with Seaborn in Python?

datavizpyr · December 26, 2019 ·

When you have multiple variables you might want to quickly look at how each variable is distributed and how each variable is related to other variables. Basically, we are interested in histograms of each variable and scatter plots for all pairs of variables.

Seaborn’s pairplot enables us to make such a plot containing a matrix of bunch of plots.

In this tutorial, we will see multiple examples of making Pairplot or scatter plot matrix using Seaborn’s pairplot() function.

Let us first load Seaborn and Matplotlib for making the pairplot.

 
import seaborn as sns
import matplotlib.pyplot as plt

Let us use Seattle weather data available from vega_datasets. We import data from vega_datasets package.

 
from vega_datasets import data
seattle_weather = data.seattle_weather()

Seattle weather data contains six columns.

 

print(seattle_weather.head(n=3))
       date  precipitation  temp_max  temp_min  wind  weather
0 2012-01-01            0.0      12.8       5.0   4.7  drizzle
1 2012-01-02           10.9      10.6       2.8   4.5     rain
2 2012-01-03            0.8      11.7       7.2   2.3     rain

Simple Pairplot with Seaborn

To make simplest pairplot, we provide the dataframe containing multiple variables as input to Seaborn’s pairplot() function.

 
sns.pairplot(seattle_weather)

We get a pairplot matrix containing histograms for each variable in the dataframe and scatter plots for all pairs of variables in the dataframe.

Scatter Matrix Plot with Seaborn
Simple Pairplot Example Seaborn

Coloring Pairplot with Seaborn

By default, Seaborn’s pairplot colors the data points in blue. We can also add colors to the pairplot based on values of a specific variable.

In this example, we color the data points using the weather variable in our data. We provide the weather variable to the argument “hue”.

 
# coloring pairplot with seaborn
sns.pairplot(seattle_weather, hue="weather")

Seaborn’s pairplot splits the data by the hue variable and makes histograms for each value of hue variable and also color data points by the variable.

Scatter Plot Matrix Colored By Variable: Seaborn
Pairplot Colored By Variable: Seaborn

Pairplot of Select variables with Seaborn

Although Seaborn’s pairplot is excellent tool for exploratory data visualization, it is not that useful if you have too many variables.

To alleviate that a bit, we can select specific variables from the data and make pairplot with them.

To select a variable of interest, we provide the variables of interest as a list to “vars” argument to Seaborn’s pairplot function.

 
# pairplot of select variables with seaborn
sns.pairplot(seattle_weather, vars=["temp_max","temp_min", "wind"], hue="weather")

In this example, we have selected variables and made a pairplot with them. We have also colored the plot using a variable from the data.

Pairplot of Select Variables Seaborn
Pairplot of Select Variables Seaborn

Related posts:

Boxplot with Catplot Seaborn PythonHow To Make Boxplots with Seaborn in Python? Grouped Barplot with SeabornHow To Make Grouped Barplots in Python with Seaborn? Grouped Boxplot with Jittered Data Points SeabornGrouped Boxplot with Jittered Points with Seaborn Python Customize Facetgrid plot titles in Seaborn_PythonHow to Customize Titles in Multi-Panel plots with Seaborn?

Filed Under: Pairplot Seaborn, Python, Seaborn Tagged With: Python, Seaborn

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version