The Wayback Machine - http://web.archive.org/web/20241001030859/https://www.geeksforgeeks.org/box-plot/
Open In App

Box Plot

Last Updated : 12 Mar, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

In this article, we are going to discuss components of a box plot, how to create a box plot, uses of a Box Plot, and how to compare box plots.

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.

Image

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-

Image

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.

Use-Cases of Box Plot

  • Box plots provide a visual summary of the data with which we can quickly identify the average value of the data, how dispersed the data is, whether the data is skewed or not (skewness).
  • The Median gives you the average value of the data.
  • Box Plots shows Skewness of the data-
a) If the Median is at the center of the Box and the whiskers are almost the 
   same on both the ends then the data is Normally Distributed.
b) If the Median lies closer to the First Quartile and if the whisker at the lower
   end is shorter (as in the above example) then it has a Positive Skew (Right Skew).
c) If the Median lies closer to the Third Quartile and if the whisker at the
   upper end is shorter than it has a Negative Skew (Left Skew).


Image

  • The dispersion or spread of data can be visualized by the minimum and maximum values which are found at the end of the whiskers.
  • The Box plot gives us the idea of about the Outliers which are the points which are numerically distant from the rest of the data.

How to compare box plots?

As we have discussed at the beginning of the article that box plots make comparing characteristics of data between categories very easy. Let us have a look at how we can compare different box plots and derive statistical conclusions from them.

Let us take the below two plots as an example: –

Image

  • Compare the Medians — If the median line of a box plot lies outside the box of the other box plot with which it is being compared, then we can say that there is likely to be a difference between the two groups. Here the Median line of the plot B lies outside the box of Plot A.
  • Compare the Dispersion or Spread of data — The Inter Quartile range (length of the box) gives us an idea about how dispersed the data is. Here Plot A has a longer length than Plot B which means that the dispersion of data is more in plot A as compared to plot B. The length of whiskers also gives an idea of the overall spread of data. The extreme values (minimum &maximum) give the range of data distribution. Larger the range more scattered the data. Here Plot A has a larger range than Plot B.
  • Comparing Outliers — The outliers give the idea of unusual data values which are distant from the rest of the data. More number of Outliers means the prediction will be more uncertain. We can be more confident while predicting the values for a plot which has less or no outliers.
  • Compare Skewness — Skewness gives us the direction and the magnitude of the lack of symmetry. We have discussed above how to identify skewness. Here Plot A is Positive or Right Skewed and Plot B is Negative or Left Skewed.

This is all for Box Plots. Now you might have got the idea of Box Plots how to make them and how to derive information from them. For any queries do leave a comment down below.

Box plot – Frequently Asked Questions (FAQs)

What do you mean by box plot?

A box plot, also known as a box-and-whisker plot, is a graphical representation of the distribution of a dataset. It summarizes key statistics such as the median, quartiles, and outliers, providing insights into the spread and central tendency of the data.

Box Plot is used for which type of data?

Box Plots gives a visual summary of the variability of values of dataset. Boxplots usually shows the numeric data values, especially is you want to compare multiple groups.

What information cannot be found in a box plot?

Information that are missed in a box plot is the detailed shape of the distribution. It is quite difficult to find the mean as it is visual representation of the data.

Is Box Plot vertical or horizontal?

Box Plot can either be drawn horizontally or vertically. It depends on the estimate L-estimators, range, mid-range and trimean.



Previous Article
Next Article

Similar Reads

Overlaying Box Plot on Swarm Plot in Seaborn
Seaborn is a powerful Python library built on top of Matplotlib, designed for creating attractive and informative statistical graphics. It provides a high-level interface for drawing attractive and informative statistical graphics, making it easier to create complex visualizations with less code. One of the key features of Seaborn is its ability to
4 min read
Box plot visualization with Pandas and Seaborn
Box Plot is the visual representation of the depicting groups of numerical data through their quartiles. Boxplot is also used for detect the outlier in data set. It captures the summary of the data efficiently with a simple box and whiskers and allows us to compare easily across groups. Boxplot summarizes a sample data using 25th, 50th and 75th per
2 min read
Understanding different Box Plot with visualization
Let's see how can boxplot be useful in different ways. Loading Libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt Preparing Data spread = np.random.rand(50) * 100 center = np.ones(25) * 50 flier_high = np.random.rand(10) * 100 + 100 flier_low = np.random.rand(10) * -100 data = np.concatenate((spread, center, flier_high
2 min read
What is Box plot and the condition of outliers?
Box plot is a data visualization plotting function. It shows the min, max, median, first quartile, and third quartile. All of the things will be explained briefly. All of the property of box plot can be accessed by dataframe.column_name.describe() function. Aspects of a box plot Here is a well distributed data-set. data = [0, 1, 2, 3, 4, 5, 6] df =
3 min read
Box Plot in Python using Matplotlib
A Box Plot is also known as Whisker plot is created to display the summary of the set of data values having properties like minimum, first quartile, median, third quartile and maximum. In the box plot, a box is created from the first quartile to the third quartile, a vertical line is also there which goes through the box at the median. Here x-axis
5 min read
Box plot and Histogram exploration on Iris data
Attribute Information about data set: Attribute Information: -> sepal length in cm -> sepal width in cm -> petal length in cm -> petal width in cm -> class: Iris Setosa Iris Versicolour Iris VirginicaNumber of Instances: 150 Summary Statistics: Min Max Mean SD Class Correlation sepal length: 4.3 7.9 5.84 0.83 0.7826 sepal width: 2.0
2 min read
Plot Multiple Histograms On Same Plot With Seaborn
Histograms are a powerful tool for visualizing the distribution of data in a dataset. When working with multiple datasets or variables, it can be insightful to compare their distributions side by side. Seaborn, a python data visualization package offers powerful tools for making visually appealing maps and efficient way to plot multiple histograms
3 min read
How To Align Kde Plot With Strip Plot In Seaborn?
A high-level interface for creating attractive and informative statistical graphics is offered by a powerful python library Seaborn. One of the most common tasks in data visualization is aligning different types of plots in one graph to gain insights into the data. In this article, we will understand and implement how to align a KDE (Kernel Density
4 min read
Plot Logistic Regression Line Over Heat Plot in R
Plotting a logistic regression line over a heat plot can be a powerful way to visualize the relationship between predictor variables and a binary outcome. This article will guide you through the steps to create such a visualization in R. What is a Logistic Regression Line?In logistic regression, the logistic regression line is the decision boundary
4 min read
How to Plot a Vertical Line on a Time Series Plot in Pandas
When working with time series data in Pandas, it is often necessary to highlight specific points or events in the data. One effective way to do this is by plotting vertical lines on the time series plot. In this article, we will explore how to plot a vertical line on a time series plot in Pandas, covering the necessary steps, functions, and paramet
3 min read
Add Moving Average Plot to Time Series Plot in R
In time series analysis, a moving average is a widely used technique to smooth out short-term fluctuations and highlight longer-term trends or cycles. R provides several ways to compute and visualize moving averages alongside time series data. This article will guide you through the process of adding a moving average plot to a time series plot in R
3 min read
Box Blur Algorithm - With Python implementation
The pixels in an image are represented as integers. After blurring each pixel 'x' of the resulting image has a value equal to the average of the pixels surrounding 'x' including 'x'. For example, consider a 3 * 3 image as [Tex] image = \begin{bmatrix} 1 & 1 & 1\\ 1 & 7 & 1\\ 1 & 1 & 1 \end{bmatrix} [/Tex] Then, the resulting
4 min read
Python | Box-Cox Transformation
Imagine you are watching a horse race and like any other race, there are fast runners and slow runners. So, logically speaking, the horse which came first and the fast horses along with it will have the smaller difference of completion time whereas the slowest ones will have a larger difference in their completion time. We can relate this to a very
5 min read
Bounding Box Prediction using PyTorch
In the realm of computer vision, PyTorch has emerged as a powerful framework for developing sophisticated models. One fascinating application within this field is bounding box prediction, a crucial task for object detection. In this article, we delve into the world of bounding box prediction using PyTorch, providing a step-by-step guide and insight
7 min read
Box Office Revenue Prediction Using Linear Regression in ML
When a movie is produced then the director would certainly like to maximize his/her movie's revenue. But can we predict what will be the revenue of a movie by using its genre or budget information? This is exactly what we'll learn in this article, we will learn how to implement a machine learning algorithm that can predict a box office revenue by u
5 min read
Why Deep Learning is Black Box
Deep learning is often referred to as a "black box" due to its complex and opaque nature, which makes it challenging to understand and interpret the inner workings of the models. Table of Content High ComplexityNon-linear TransformationsLayer-wise AbstractionDistributed RepresentationsLack of TransparencyInterpretability TechniquesConclusionHere ar
3 min read
Box-Jenkins Methodology for ARIMA Models
Time series data records data points with respect to time intervals. The analysis of such dataset is important to recognize patterns and making predictions as well as providing informative insights. Box-Jenkins model is a forecasting method that is used to forecasts time series data for a specific period of time. In this article we will be taking a
11 min read
Black Box Problem in AI
Artificial Intelligence (AI) has seen exponential growth and adoption across various industries, from healthcare to finance, and even in everyday consumer products. Despite its significant advancements, AI is not without its challenges. One of the most pressing issues is the Black Box Problem, which describes the lack of transparency in AI systems,
7 min read
Aligning Violin Plots with Dodged Box Plots
Combining violin plots and box plots can offer a detailed view of the data distribution, making it easier to spot the overall shape (via the violin plot) while also observing key summary statistics like the median, quartiles, and outliers (via the box plot). However, aligning them side by side, especially with dodging (i.e., separating the plots fo
5 min read
Plot Single 3D Point on Top of plot_surface in Python - Matplotlib
Matplotlib is a widely-used plotting library in Python that offers various tools and functionalities for creating 2D and 3D visualizations. In this article, we will explore how to use Matplotlib to plot a single 3D point on top of a 3d surface plot. Plot Single 3D Point on Top of SurfaceLet us understand the Plotting single 3D point on top of the p
5 min read
Introduction to Bootstrap plot
Before getting into Bootstrap plot, let us first understand what Bootstrapping (or Bootstrap sampling) is all about. Bootstrap Sampling: It is a method in which we take a sample data repeatedly with replacement from a data set to estimate a population parameter. It is used to determine various parameters of a population. A bootstrap plot is a graph
5 min read
qqplot (Quantile-Quantile Plot) in Python
When the quantiles of two variables are plotted against each other, then the plot obtained is known as quantile - quantile plot or qqplot. This plot provides a summary of whether the distributions of two variables are similar or not with respect to the locations. Interpretations All point of quantiles lie on or close to straight line at an angle of
2 min read
Make an area plot in Python using Bokeh
Bokeh is a Python interactive data visualization. Unlike Matplotlib and Seaborn, Bokeh renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Plotting the Area Plots Area plots are defined as the filled regions betwee
2 min read
Python Bokeh - Plotting a Scatter Plot on a Graph
Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to plot a scatter plot on a graph. Plotting squares on a graph can be done using the scatte
2 min read
Plot Candlestick Chart using mplfinance module in Python
Candlestick chart are also known as a Japanese chart. These are widely used for technical analysis in trading as they visualize the price size within a period. They have four points Open, High, Low, Close (OHLC). Candlestick charts can be created in python using a matplotlib module called mplfinance. Installation:pip install mplfinancemplfinance.ca
2 min read
How to Plot Mean and Standard Deviation in Pandas?
Errorbar is the plotted chart that refers to the errors contained in the data frame, which shows the confidence & precision in a set of measurements or calculated values. Error bars help in showing the actual and exact missing parts as well as visually display the errors in different areas in the data frame. Error bars are the descriptive behav
3 min read
Sunburst Plot using graph_objects class in plotly
Plotly is a Python library which is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library. Sunburst Plot using graph_objects class If Plotl
3 min read
Probability plot correlation coefficient
The probability plot correlation coefficient (PPCC) is a graphical technique for identifying the shape parameter that best describes the dataset. Most of the statistical analysis has been done assuming the shape of the distribution in mind. However, these assumptions may be challenged because sometimes the distributions can have very different shap
4 min read
How to plot data from a text file using Matplotlib?
Perquisites: Matplotlib, NumPy In this article, we will see how to load data files for Matplotlib. Matplotlib is a 2D Python library used for Date Visualization. We can plot different types of graphs using the same data like: Bar GraphLine GraphScatter GraphHistogram Graph and many. In this article, we will learn how we can load data from a file to
3 min read
How to Make a Time Series Plot with Rolling Average in Python?
Time Series Plot is used to observe various trends in the dataset over a period of time. In such problems, the data is ordered by time and can fluctuate by the unit of time considered in the dataset (day, month, seconds, hours, etc.). When plotting the time series data, these fluctuations may prevent us to clearly gain insights about the peaks and
4 min read