0% found this document useful (0 votes)
29 views6 pages

Understanding Box Plots and Quartiles

Uploaded by

aitscserd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

Understanding Box Plots and Quartiles

Uploaded by

aitscserd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Box Plot

Box Plot is a graphical method to visualize data distribution for gaining insights and making informed
decisions. Box plot is a type of chart that depicts a group of numerical data through their quartiles.

What is a Box Plot?

The idea of box plot was presented by John Tukey in 1970. He wrote about it in his book "Exploratory
Data Analysis" in 1977. Box plot is also known as a whisker plot, box-and-whisker plot, or simply a
box-and whisker diagram. Box plot is a graphical representation of the distribution of a dataset. It
displays key summary statistics such as the median, quartiles, and potential outliers in a concise and
visual manner. By using Box plot you can provide a summary of the distribution, identify potential
and compare different datasets in a compact and visual manner.

Elements of Box Plot

A box plot gives a five-number summary of a set of data which is-

 Minimum - It is the minimum value in the dataset excluding the outliers.

 First Quartile (Q1) - 25% of the data lies below the First (lower) Quartile.

 Median (Q2) - It is the mid-point of the dataset. Half of the values lie below it and half
above.

 Third Quartile (Q3) - 75% of the data lies below the Third (Upper) Quartile.

 Maximum - It is the maximum value in the dataset excluding the outliers.

Structure of a Boxplot

 Box → spans from Q1 to Q3 (Interquartile Range, IQR).

 Line inside the box → median (Q2).

 Whiskers → extend to minimum and maximum values within 1.5 × IQR from the box.

 Dots beyond whiskers → outliers.

📌 Formula:

 IQR = Q3 – Q1
 Lower whisker limit = Q1 – 1.5 × IQR

 Upper whisker limit = Q3 + 1.5 × IQR

Note: The box plot shown in the above diagram is a perfect plot with no skewness. The plots can
have skewness and the median might not be at the center of the box.

The area inside the box (50% of the data) is known as the Inter Quartile Range. The IQR is calculated
as -

IQR = Q3-Q1

Outlies are the data points below and above the lower and upper limit. The lower and upper limit is
calculated as -

Lower Limit = Q1 - 1.5*IQR

Upper Limit = Q3 + 1.5*IQR

The values below and above these limits are considered outliers and the minimum and maximum
values are calculated from the points which lie under the lower and upper limit.

How to create a box plots?

Let us take a sample data to understand how to create a box plot.

Here are the runs scored by a cricket team in a league of 12 matches - 100, 120, 110, 150, 110, 140,
130, 170, 120, 220, 140, 110.

To draw a box plot for the given data first we need to arrange the data in ascending order and then
find the minimum, first quartile, median, third quartile and the maximum.

Ascending Order

100, 110, 110, 110, 120, 120, 130, 140, 140, 150, 170, 220

Median (Q2) = (120+130)/2 = 125; Since there were even values

To find the First Quartile we take the first six values and find their median.

Q1 = (110+110)/2 = 110

For the Third Quartile, we take the next six and find their median.

Q3 = (140+150)/2 = 145

Note: If the total number of values is odd then we exclude the Median while calculating Q1 and Q3.
Here since there were two central values we included them. Now, we need to calculate the Inter
Quartile Range.

IQR = Q3-Q1 = 145-110 = 35


We can now calculate the Upper and Lower Limits to find the minimum and maximum values and
also the outliers if any.

Lower Limit = Q1-1.5*IQR = 110-1.5*35 = 57.5

Upper Limit = Q3+1.5*IQR = 145+1.5*35 = 197.5

So, the minimum and maximum between the range [57.5,197.5] for our given data are -

Minimum = 100

Maximum = 170

The outliers which are outside this range are -

Outliers = 220

Now we have all the information, so we can draw the box plot which is as below-

We can see from the diagram that the Median is not exactly at the center of the box and one whisker
is longer than the other. We also have one Outlier.

CODE:
import numpy as np

import [Link] as plt

# Data (runs scored)

runs = [100, 120, 110, 150, 110, 140, 130, 170, 120, 220, 140, 110]

# Step 1: Arrange in ascending order

runs_sorted = sorted(runs)

print("Ascending Order:", runs_sorted)


# Step 2: Calculate five-number summary

minimum = [Link](runs_sorted)

q1 = [Link](runs_sorted, 25)

median = [Link](runs_sorted)

q3 = [Link](runs_sorted, 75)

maximum = [Link](runs_sorted)

print(f"Minimum: {minimum}")

print(f"Q1 (25th percentile): {q1}")

print(f"Median (Q2): {median}")

print(f"Q3 (75th percentile): {q3}")

print(f"Maximum: {maximum}")

# Step 3: Draw Boxplot

[Link](figsize=(6,4))

[Link](runs_sorted, vert=True, patch_artist=True,

boxprops=dict(facecolor="skyblue", color="black"),

medianprops=dict(color="red"))

[Link]("Boxplot of Runs Scored in 12 Matches")

[Link]("Runs")

[Link]()
Example 2 – Students’ Marks in 10 Exams

Marks scored by a student in 10 exams:

45, 50, 60, 40, 55, 70, 65, 80, 90, 85

Step 1: Arrange in Ascending Order

40, 45, 50, 55, 60, 65, 70, 80, 85, 90

Step 2: Find Five-Number Summary

 Minimum (lowest value): 40

 Maximum (highest value): 90

 Median (Q2): Middle value = average of 5th and 6th values = (60 + 65)/2 = 62.5

 Q1 (25th percentile): Median of lower half = (50 + 55)/2 = 52.5

 Q3 (75th percentile): Median of upper half = (70 + 80)/2 = 75

So the five-number summary is:


👉 Min = 40, Q1 = 52.5, Median = 62.5, Q3 = 75, Max = 90

Step 3: Python Code to Plot Boxplot

import numpy as np

import [Link] as plt

# Data (marks in exams)

marks = [45, 50, 60, 40, 55, 70, 65, 80, 90, 85]

# Arrange in ascending order

marks_sorted = sorted(marks)

print("Ascending Order:", marks_sorted)

# Five-number summary

minimum = [Link](marks_sorted)

q1 = [Link](marks_sorted, 25)

median = [Link](marks_sorted)
q3 = [Link](marks_sorted, 75)

maximum = [Link](marks_sorted)

print(f"Minimum: {minimum}")

print(f"Q1: {q1}")

print(f"Median: {median}")

print(f"Q3: {q3}")

print(f"Maximum: {maximum}")

# Boxplot

[Link](figsize=(6,4))

[Link](marks_sorted, vert=True, patch_artist=True,

boxprops=dict(facecolor="lightgreen", color="black"),

medianprops=dict(color="red"))

[Link]("Boxplot of Marks Scored in 10 Exams")

[Link]("Marks")

[Link]()

✅ This example works just like your cricket runs dataset but with exam marks.
👉 Do you want me to also add outliers in this dataset (like a very low or very high mark) so you can
see how outliers appear in a boxplot?

You might also like