How to visualize KDE Plot using Seaborn?

We learn the usage of some parameters through some specific examples:

Importing Libraries

First import the corresponding library

Python3




import pandas as pd
import seaborn as sb
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline


Draw a simple one-dimensional kde image:

Let’s see the Kde of our variable x-axis and y-axis, so let pass the x variable into the kdeplot() methods.

Python3




# data x and y axis for seaborn
x= np.random.randn(200)
y = np.random.randn(200)
 
# Kde for x var
sns.kdeplot(x)


Output:

Then after check for y-axis.

Python3




sns.kdeplot(y)


Output:

Use Shade to fill the area covered by curve:

We can highlight the plot using shade to the area covered by the curve. If True, shadow processing is performed in the area below the kde curve, and color controls the color of the curve and shadow.

Python3




sns.kdeplot(x, shade = True)


Output:

You can change the Shade color with color attributes:

Python3




sns.kdeplot(x, shade = True , color = "Green")


Output:

Use Vertical to draw indicates whether to draw on the X axis or on the Y axis

Python3




sns.kdeplot(x, vertical = True)


Output:

Bivariate Kdeplot for two variables: 

Simple pass the two variables into the seaborn.kdeplot() methods.

Python3




sns.kdeplot(x,y)


Output:

Shade the area covered by a curve with shade attributes:

Python3




sns.kdeplot(x,y, shade = True)


Output:

Now you can change the color with cmap attributes:

Python3




sns.kdeplot(x,y, cmap = "winter_r")


Output:

Use of Cbar: If True, add a colorbar to annotate the color mapping in a bivariate plot. Note: Does not currently support plots with a hue variable well.

Python3




sns.kdeplot(x, y, shade=True, cbar=True)


Output:

Seaborn Kdeplot – A Comprehensive Guide

Kernel Density Estimate (KDE) Plot is a powerful tool for estimating the probability density function of continuous or non-parametric data. KDE plot is implemented through the kdeplot function in Seaborn. This article explores the syntax and usage of kdeplot in Python, focusing on one-dimensional and bivariate scenarios for efficient data visualization.

Table of Content

  • What is KDE plot?
  • How to visualize KDE Plot using Seaborn?
  • KDE Plot of Iris Dataset
  • Conclusion
  • Frequently Asked Questions (FAQs)

Similar Reads

What is KDE plot?

Kernel Density Estimate (KDE) Plot allows to estimate the probability density function of the continuous or non-parametric from our data set curve in one or more dimensions it means we can create plot a single graph for multiple samples which helps in more efficient data visualization....

How to visualize KDE Plot using Seaborn?

We learn the usage of some parameters through some specific examples:...

KDE Plot of Iris Dataset

...

Conclusion

...

Frequently Asked Questions (FAQs)

...