To plot a KDE in Seaborn, we use the method
A KDE plot takes the following arguments:
data- the univariate dataset being visualized, like a Pandas DataFrame, Python list, or NumPy array
shade- a boolean that determines whether or not the space underneath the curve is shaded
Let’s examine the KDE plots of our three datasets:
sns.kdeplot(dataset1, shade=True) sns.kdeplot(dataset2, shade=True) sns.kdeplot(dataset3, shade=True) plt.legend() plt.show()
Notice that when using a KDE we need to plot each of the original datasets separately, rather than using a combined dataframe like we did with the bar plot.
It looks like there are some big differences between the three datasets:
- Dataset 1 is skewed left
- Dataset 2 is normally distributed
- Dataset 3 is bimodal (it has two peaks)
So although all three datasets have roughly the same mean, the shapes of the KDE plots demonstrate the differences in how the values are distributed.
sns.kdeplot() to graph the four datasets and set
plt.show() to display the KDE plots.