Introduction
In this tutorial, we want to create a Pairplot. In order to do this, we use the pairplot() function of Seaborn.
Import Libraries
First, we import the following python modules:
import seaborn as sns
import matplotlib.pyplot as plt
Load Data
We would like to use a seaborn sample dataset. Let's load the "iris" dataset into python.
iris_df = sns.load_dataset("iris")
iris_df.head()
Pairplot
With Pairplots, the distribution of each numeric variable and the relation to the other variables in the dataset can be visualized. Therefore Pairplots can be very useful for exploratory data analysis.
Example 1: Simple Pairplot
Now, we would like to visualize the iris data with a Pairplot. Let's generate a simple Pairplot.
sns.pairplot(data=iris_df)
plt.show()
Example 2: Pairplot for two specific variables
Now, we generate a pairplot only for the two columns "sepal_length" and "sepal_width".
sns.pairplot(data=iris_df, vars=["sepal_length","sepal_width"])
plt.show()
Example 3: Pairplot with Grouping
Now, we want to highlight the species. In order to do this, we use the hue parameter and set it to "species".
Example 4: Set Graph Type
Now, let's use the kind parameter and set it to "kde".
sns.pairplot(data=iris_df, kind="kde")
plt.show()
Example 5: Remove Upper Triangle
Now, we want to plot only the lower triangle. In order to do this, we use the corner parameter and set it to True.
sns.pairplot(data=iris_df, corner=True)
plt.show()
Conclusion
Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to create a Pairplot. We can simply use the pairplot() function of Seaborn. Try it yourself!
Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.