Learn

One advantage of the box plot over the KDE plot is that in Seaborn, it is easy to plot multiples and compare distributions.

Let’s look again at our three datasets, and how they look plotted as box plots:

sns.boxplot(data=df, x='label', y='value') plt.show()

The box plot does a good job of showing certain differences, like those between Dataset 1 and Dataset 2; however, it does not show that Dataset 3 is bimodal.

To plot a box plot in Seaborn, we use the method sns.boxplot().

A box plot takes the following arguments:

  • data - the dataset we’re plotting, like a DataFrame, list, or an array
  • x - a one-dimensional set of values, like a Series, list, or array
  • y - a second set of one-dimensional data

If you use a Pandas Series for the x and y values, the Series will also generate the axis labels. For example, if you use the value Series as your y value data, Seaborn will automatically apply that name as the y-axis label.

Instructions

1.

Use sns.boxplot() to plot the four datasets as box plots.

2.

Use plt.show() to display the box plots. What else can we learn about these datasets?

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?