# 4.4.4 Pairplot

A pair plot pairwise relationships in a dataset. The pair plot function creates a grid of Axes such that each variable in data will be shared in the y-axis across a single row and in the x-axis across a single column. The diagonal Axes are treated differently, drawing a plot to show the univariate distribution of the data for the variable in that column.

```
import seaborn as sns
plt.rcParams.update({'font.size': 18,'figure.figsize':(8, 6)})
tips = sns.load_dataset("tips")
```

![Head of Tips Dataset](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCZ5WVj9VZNxiMeRkUZ%2F-MCZ96jP3gfnOQEUyvg_%2FScreenshot%202020-07-19%20at%2001.00.27.png?alt=media\&token=7603a038-9b73-44c9-acb1-99ddd6103b4d)

Let's draw a simple scatterplot for joint relationships and univariate distribution.

```
sns.pairplot(tips)
```

![](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCZ5WVj9VZNxiMeRkUZ%2F-MCZ876u2O7eqYvfpH-q%2Fdownload-1.png?alt=media\&token=e20d5ae5-69a0-49e9-97ef-2aeec15879e1)

If you have a large dataset, you may consider a "**small and specific**" method to illustrate a subset of variables. Then we can use `vars`. Compare to the whole dataset, below only shows the relationship between tip and table size.

```
sns.pairplot(tips, vars=["tip", "size"])
```

![](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCZ5WVj9VZNxiMeRkUZ%2F-MCZ9j8bOliBW_AeSC_a%2Fdownload.png?alt=media\&token=34af5f13-eee3-4834-9b9f-10d332703ead)

Considering the simplicity, it's possible to remove the repetitive part and leave a lower triangle of bivariate axes.

```
sns.pairplot(tips,corner = True)
```

![](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCZ5WVj9VZNxiMeRkUZ%2F-MCZ9yey8Vnxvvmh--No%2Fdownload-5.png?alt=media\&token=1853b811-72c6-4948-b50a-aa9804a955e4)

If you want to represent an additional level of conditionalization. Then we can use the parameter`hue` , which plots different subsets of data in different colors. Here is an example of showing different levels of a categorical variable by colors.

```
sns.pairplot(tips, kind="reg",hue = 'smoker',palette = 'husl')
```

![](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCZ5WVj9VZNxiMeRkUZ%2F-MCZ9HficuzP9B035n8y%2Fdownload-3.png?alt=media\&token=49ebb0c8-506d-42fa-a718-0f9e16626baa)

Also, we can use different`markers`for each level of the hue variable, to illustrate the difference.

```
sns.pairplot(tips, kind="scatter",hue ='sex',markers=["o", "s"],palette = 'husl')
```

![](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCZ5WVj9VZNxiMeRkUZ%2F-MCZ9PTPQ5L0dkjIuW26%2Fdownload-4.png?alt=media\&token=b3f90c4b-9d66-4c58-a368-52649b99a927)
