w3resource

Python Scikit-learn: Create a kde plot of two shaded bivariate densities of Sepal Width and Sepal Length

Python Machine learning Iris Visualization: Exercise-16 with Solution

Write a Python program using seaborne to create a kde (Kernel Density Estimate) plot of two shaded bivariate densities of Sepal Width and Sepal Length.

Sample Solution:

Python Code:

# Import necessary modules 
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt 
iris = pd.read_csv("iris.csv")
#Drop id column
iris = iris.drop('Id',axis=1)
sns.kdeplot(data=sub[['PetalLengthCm','PetalWidthCm']],cmap="plasma", shade=True, shade_lowest=False)
plt.title('Iris-setosa')
plt.xlabel('Petal Length Cm')
plt.ylabel('Petal Width Cm')
plt.show()

Output:

Python Machine learning Output: Iris Visualization: Exercise-16
 

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program using seaborn to create a kde (Kernel Density Estimate ) plot of petal_length versus petal width for setosa species of flower.

Next: Write a Python program to find the correlation between variables of iris data. Also create a hitmap using Seaborn to present their relations.

What is the difficulty level of this exercise?