Box Plot in Python using Matplotlib

matplotlib.pyplot.boxplot(): Here, we are going to learn about the Box Plot in Python using Matplotlib and its implementation.
Submitted by Anuj Singh, on July 23, 2020

Making a box plot or whisker plot for each column of x (if x is a matrix) or vector x includes creating a box that extends from the lower quartile to upper quartile values of data. It also has a line right at the median of the datapoint (each column of the matrix in the case of the matrix). It also includes outliers as fliers points and is represented by dots. In this way, it helps in visualizing the definitive range of data and therefore it is important to get to know about how we can plot BoxPlot in python. Matplot has an inbuilt defined function for Box-Plot i.e. matplotlib.pyplot.boxplot().

The following example illustrates the basic example of the Box Plot.

Python Box Plot

Python code for box plot using matplotlib

import numpy as np
import matplotlib.pyplot as plt

# Generating Data
spread = np.random.rand(65) * 82
center = np.ones(36) * 50
flier_high = np.random.rand(12) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low))

plt.title('Basic Box Plot')


Output is as figure


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.