w3resource

Python Scikit-learn: Create a kde plot of petal_length versus petal width for setosa species of flower

Python Machine learning Iris Visualization: Exercise-15 with Solution

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.

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-15
 

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 sepal_length versus sepal width for setosa species of flower.

Next: 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.

What is the difficulty level of this exercise?