Introduction
In this article, we will go through the tutorial for Seaborn Pairplot using pairplot() function that can be useful for exploratory data analysis for your machine learning projects. We will understand the syntax of pairplot() function of the seaborn library and then see various examples of it.
Seaborn Pairplot Tutorial
The pairplot() function of seaborn helps in creating an axes grid through which each numeric variable present in data is shared across y-axes in the form of rows and across x-axes in form of a column. Scatter plots are created to show pairwise relationships and in the diagonal, the distribution plot is created to show the distribution of the data in the column.
We can also use pairplot for showcasing variables subset or even for plotting several types of variables on rows and columns.
Let us understand the syntax of the pairplot() function below.
Seaborn Pairplot Syntax
seaborn.pairplot(data, *, hue=None, hue_order=None, palette=None, vars=None, x_vars=None, y_vars=None, kind=’scatter’, diag_kind=’auto’, markers=None, height=2.5, aspect=1, corner=False, dropna=False, plot_kws=None, diag_kws=None, grid_kws=None, size=None)
- data : DataFrame, array, or list of arrays, optional
This parameter takes the data based on which the visualization will be plotted.
- order, hue_order : lists of strings, optional
This is the order for categorical variables used in the plot.
- scale : {“area”, “count”, “width”}, optional
The method used to scale the plot. It has multiple values for usage.
- scale_hue : bool, optional
When nesting violins using a hue variable, this parameter determines whether the scaling is computed within each level of the major grouping variable (scale_hue=True) or across all the violins on the plot (scale_hue=False).
- gridsize : int, optional
These are the points used to calculate the kernel density estimate for the plot.
- inner : {“box”, “quartile”, “point”, “stick”, None}, optional
This parameter helps in defining the inner points of a violin plot.
- orient : “v” | “h”, optional
This parameter can help in deciding the orientation of the plot. It can be either horizontal or vertical.
- linewidth : float, optional
This is the width of gray lines used inside the plot.
- color : matplotlib color, optional
This will help in specifying the color for all the elements of the plot.
- palette : palette name, list, or dict
The palette defines the colors used for different levels of the plot with a variety of hues.
- ax : matplotlib Axes, optional
These are the axes on which we build the plot.
1st Example – Simple Seaborn Pairplot
In the first example, we will create a simple pairplot in Seaborn by using the penguin dataset.
We just pass the dataset into the pairplot() function and that’s it, your pairplot visualization is ready.
import seaborn as sns
penguins = sns.load_dataset("penguins")
sns.pairplot(penguins)
2nd Example – Seaborn Pairplot with Hue Variable for Categorization
The 2nd example shows the way in which hue parameter can be used for plotting a pairplot. The hue parameter helps us to categorize data based on a column.
Here we pass the dataset ‘penguin’ and the column ‘species’ for hue to the pairplot() function.
sns.pairplot(penguins, hue="species")
3rd Example – Using ‘kind’ variable in Pairplot()
The third example shows how we can use the kind variable. The kind variable allows us to alter the off-diagonal plots. In this example, we are using kernel density estimation for off-diagonal plots.
sns.pairplot(penguins, kind="kde")
4th Example – Applying markers parameter to Pairplot
This example is showing how different types of markers can be used for scatter plot in the pair plot.
The shape for the markers is specified using different letters.
sns.pairplot(penguins, hue="species", markers=["o", "s", "D"], palette="rainbow")
Conclusion
We have reached the end of this seaborn tutorial. It talked about the pairplot function, its syntax, parameters used in the function along with different types of examples.
Reference: https://seaborn.pydata.org/
-
I am Palash Sharma, an undergraduate student who loves to explore and garner in-depth knowledge in the fields like Artificial Intelligence and Machine Learning. I am captivated by the wonders these fields have produced with their novel implementations. With this, I have a desire to share my knowledge with others in all my capacity.
View all posts