Learn
Learn Seaborn: Distributions
KDE Plots, Part II

To plot a KDE in Seaborn, we use the method sns.kdeplot().

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()

alt

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.

Instructions

1.

Use sns.kdeplot() to graph the four datasets and set shade to True.

2.

Use plt.show() to display the KDE plots.

Folder Icon

Sign up to start coding

Already have an account?