How Seaborn library used to display a kernel density estimation plot (joinplot) in Python?



Seaborn is a library that helps in visualizing data. It comes with customized themes and a high level interface.

Kernel Density Estimation, also known as KDE is a method in which the probability density function of a continuous random variable can be estimated. This method is used for the analysis of the non-parametric values. While using โ€˜jointplotโ€™, if the argument โ€˜kindโ€™ is set to โ€˜kdeโ€™, it plots the kernel density estimation plot.

Let us understand how the โ€˜jointplotโ€™ function works to plot a kernel density estimation in python.

Example

import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
my_df = sb.load_dataset('iris')
sb.jointplot(x = 'petal_length',y = 'petal_width',data = my_df,kind = 'kde')
plt.show()

Output

Explanation

  • The required packages are imported.

  • The input data is โ€˜iris_dataโ€™ which is loaded from the scikit learn library.

  • This data is stored in a dataframe.

  • The โ€˜load_datasetโ€™ function is used to load the iris data.

  • This data is visualized using the โ€˜jointplotโ€™ function.

  • Here, the โ€˜xโ€™ and โ€˜yโ€™ axis values are supplied as parameters.

  • Here, the โ€˜kindโ€™ parameter is specified as โ€˜kdeโ€™ so that the plot understands to print kernel density estimation.

  • This kernel density estimation data is displayed on the console.

Updated on: 2020-12-11T10:48:33+05:30

210 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements