How to Create a Box Plot with Matplotlib



A box plot helps describe a continuous variable. It will display the quantiles of the variable. For example, if we have test scores, we can see how many score fall in to groups of 25%, 50%, etc. We can also view the mean and deviation of scores by seeing the size of the box plot as well as see outliers plotted outside of the plot. In this article, we will learn how to create a Box Plot in MatPlotLib.

Creating the Box Plot

To create a box plot in MatPlotLib, we pass our data to the boxplot method of pyplot. In our example, we will look at a list of grades.

import matplotlib.pyplot as plt

grades = [40, 60, 75, 76, 80, 81, 85, 90, 99]