Skip to Content
Learn
Learn Seaborn: Distributions
Violin Plots, Part II

Violin Plots are a powerful graphing tool that allows you to compare multiple distributions at once.

Let’s look at how our original three data sets look like as violin plots:

sns.violinplot(data=df, x="label", y="value") plt.show()

alt

As we can see, violin plots allow us to graph and compare multiple distributions. It also retains the shape of the distributions, so we can easily tell that Dataset 1 is skewed left and that Dataset 3 is bimodal.

To plot a violin plot in Seaborn, use the method sns.violinplot().

There are several options for passing in relevant data to the x and y parameters:

  • data - the dataset that we’re plotting, such as a list, DataFrame, or array
  • x, y, and hue - a one-dimensional set of data, such as a Series, list, or array
  • any of the parameters to the function sns.boxplot()

Instructions

1.

Using sns.violinplot(), plot the four datasets as violin plots.

2.

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

Notice how much easier it is to compare the shape of the datasets than when they were layered on top of each other!

Folder Icon

Sign up to start coding

Already have an account?