How can Seaborn library be used to display kernel density estimations in Python?

PythonServer Side ProgrammingProgramming

Visualizing data is an important step since it helps understand what is going on in the data without actually looking at the numbers and performing complicated computations. 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 ‘distplot’, if the argument ‘kde’ is set to True and ‘hist’ is set to False, the KDE can be visualized.

Let us see how we can visualize a kernel density estimation in Python −


import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
df = sb.load_dataset('iris')
sb.distplot(df['petal_length'],kde = True, hist = False)



  • The required packages are imported.
  • The input data is ‘iris_data’ which is loaded from the scikit learn library.
  • The ‘load_dataset’ function is used to load the iris data.
  • This data is visualized using the ‘distplot’ function.
  • Here, the parameter ‘kde’ is set to true since we only want to display the histogram.
  • This visual data is displayed on the console.

Note − When the value of ‘kde’ is specified as False, only the histogram is displayed.

Published on 11-Dec-2020 10:20:39