How to Create a Box Plot in Seaborn



When viewing a contious variable, it is often helpful to calculate a few statistics such as mean, quantiles, variance and outliser. A boxplot helps you visualize this information in a simple chart. In this article, we will learn how to create a boxplot in the Seaborn library.

Creating a Box Plot

To create a box plot in Seaborn, we use the boxplot method and pass an array of our data to the x named parameter. In the exmaple below, we create a boxplot of tips so that we can see the mean, quantiles, and outliers.

import seaborn
tip = seaborn.load_dataset("tips")
seaborn.boxplot(x = tip['total_bill'])

Creating multiple Box plot

It is often the case that you want to compare a contious variable accross multiple categories. For example, let's say we want to see the summary statistics above for tips, but separate by day. This would allow us to tell if any days create the best tips.

To do this, we simply specfiy an x and y value so that x will be our categories and y would be our contious variable.

import seaborn

tip = seaborn.load_dataset('tips')
seaborn.boxplot(x = 'day',
				y = 'tip',
				data = tip)
GoTea - KoalaTea