Home »
Python »
Python Data Visualization
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 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.figure()
plt.title('Basic Box Plot')
plt.boxplot(data)
plt.ylable('Variation')
Output:
Output is as figure