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
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
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.
sns.boxplot() to plot the four datasets as box plots.
plt.show() to display the box plots. What else can we learn about these datasets?