 ## Pair Plots

A Simple 2D Scatter plot is used to understand the relationship or pattern between two variables or dimensions in our dataset. A 3D plot will be used for three variables or dimensions. However, what would do if we have more than 3 dimensions or features in our dataset as we humans do have the capability to visualize more than 3 dimensions? One solution to this problem is pair plots. It is one of the most effective starting tools.

They are used to plot features when we have more than three dimensions. As the name suggests we actually do pairs of features and plot them all.

For example, let’s say we have four features Name, Place, Animal and Thing in our dataset. In that case, we will have 4C2 plots i.e. 6 unique plots. The pairs in this case will be i. (Name, Place); ii. (Name, Animal); iii. (Name, Thing); iv. (Place, Animal); v. (Place, Thing) and vi. (Animal, Thing).

So, here instead of trying to visualise four dimensions which is not possible. We will look into 6 2D plots and try to understand the 4-dimensional data in the form of a matrix.

## Some Basic Points To Remember Whenever We Are Looking At Pair Plots:

1. We will receive a matrix of plots where we will have an equal number of plots on both sides of the diagonal which would be the mirror image of each other. So, we should either look at the plots below the diagonal or above the diagonal, unless we use pairgrids.
2. We should always try to understand the legends

It is simply amazing to see just one simple line of code to gives us the entire plot.

Instead of writing codes for plotting 2D scatter plot individually. We can just write one line of code and we have our pair plots.

```#Creating a simple pair plot
sns.pairplot(knowledge)
plt.show()
```

We can make these charts more interesting by assigning them class labels

```#Giving the pair plot class labelssns.pairplot(knowledge, hue = ' UNS')plt.show()
```

## As Seen Above The Pair Plots Can Be Divided Into Three Parts:

• The diagonal plot which showcases the histogram. The histogram allows us to see the distribution of a single variable
• Upper triangle and lower triangle which shows us the scatter plot. The scatter plots show us the relationship between the features. These upper and lower triangles are the mirror image of each other.

However, python gives us some amazing tools to customise our pair plots in the form of pair grids. Here, we can customise as to what we want to see in our three parts of the plot. For example: We can see that in the figure mentioned below, we have the option of choosing different types of plots in the upper triangle, diagonal and the lower triangle.

```# Create a pair plot colored by the knowledge
level of user with a density plot of the # diagonal and format the scatter
plots.sns.pairplot(knowledge, hue = ' UNS', diag_kind = 'kde', palette='hls',     plot_kws = {'alpha': 0.9, 's': 80, 'edgecolor': 'k'},
size = 4)
plt.show()
```
```# Create an instance of the PairGrid class.grid = sns.PairGrid(data= knowledge, size = 4)
# Map a scatter plot to the upper trianglegrid = grid.map_upper(plt.scatter, color = 'darkred')# Map a histogram to the diagonalgrid = grid.map_diag(plt.hist, bins = 10, color = 'darkred',
edgecolor = 'k')# Map a density plot to the lower trianglegrid = grid.map_lower(sns.kdeplot, cmap = 'Reds')plt.show()

```