In this tutorial, we want to create a Boxplot. In order to do this, we use the boxplot() function of Seaborn.

Import Libraries

First, we import the following python modules:

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pandas as pd

Define Data

Let's define our example data. We consider the exam results of a university class. The number of points ranges from 0 to 100. We consider a class with 20 students that took part in five exams.

exam_result = np.random.randint(100, size=(20,5))


Create DataFrame

Now, we would like to store our generated data in a DataFrame:

df = pd.DataFrame(exam_result, columns=['Machine Learning',
                                        'Computer Science', 
                                        'Neural Networks', 

Plot Boxplot

Next, we would like to visualize the exam results with a boxplot. In order to do this, we use the boxplot() function of Seaborn.

#Set figure size
f = plt.figure()

# plotting the boxplot
boxplot = sns.boxplot(data = df)
# displaying the boxplot


Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to create a Boxplot. We can simply use the boxplot() function of Seaborn. Try it yourself!


Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.