Wednesday, December 25, 2024
Google search engine
HomeLanguagesPython – seaborn.pairplot() method

Python – seaborn.pairplot() method

Prerequisite: Seaborn Programming Basics

Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major issues while working with Matplotlib:

  • Default Matplotlib parameters
  • Working with data frames

As Seaborn compliments and enhances Matplotlib, the learning curve is quite gradual. If you are familiar with Matplotlib, you are already halfway done with Seaborn.

seaborn.pairplot() :

To plot multiple pairwise bivariate distributions in a dataset, you can use the .pairplot() function. 

The diagonal plots are the univariate plots, and this displays the relationship for the (n, 2) combination of variables in a DataFrame as a matrix of plots.

                        seaborn.pairplot( data, \*\*kwargs )

Seaborn.pairplot uses many arguments as input, main of which are described below in form of table:

Arguments                           Description Value                                                                                                        
data Tidy (long-form) dataframe where each column is a variable, and each row is an observation. DataFrame
hue Variable in “data“ to map plot aspects to different colors. string (variable name), optional
palette Set of colors for mapping the “hue“ variable. In case of a dict, the keys should be values in the “hue“ variable. vars: list of variable names, optional dict or seaborn color palette
{x, y}_vars Variables within “data“ to use separately for the rows and columns of the figure, i.e., to make a non-square plot. lists of variable names, optional
dropna Drop missing values from the data before plotting. boolean, optional

Below is the implementation of above method:

Example 1:

Python3




# importing packages
import seaborn
import matplotlib.pyplot as plt
 
############# Main Section ############
# loading dataset using seaborn
df = seaborn.load_dataset('tips')
# pairplot with hue sex
seaborn.pairplot(df, hue ='sex')
# to show
plt.show()
 
# This code is contributed by Deepanshu Rustagi.


 
 

Output :

Example 2:

 

Python3




# importing packages
import seaborn
import matplotlib.pyplot as plt
 
############# Main Section ############
# loading dataset using seaborn
df = seaborn.load_dataset('tips')
# pairplot with hue day
seaborn.pairplot(df, hue ='day')
# to show
plt.show()
 
# This code is contributed by Deepanshu Rustagi.


 
 

Output :

 

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments