English 中文(简体)
Matplotlib - Box Plot
  • 时间:2024-12-22

Matplotpb - Box Plot


Previous Page Next Page  

A box plot which is also known as a whisker plot displays a summary of a set of data containing the minimum, first quartile, median, third quartile, and maximum. In a box plot, we draw a box from the first quartile to the third quartile. A vertical pne goes through the box at the median. The whiskers go from each quartile to the minimum or maximum.

Box Plot

Let us create the data for the boxplots. We use the numpy.random.normal() function to create the fake data. It takes three arguments, mean and standard deviation of the normal distribution, and the number of values desired.

np.random.seed(10)
collectn_1 = np.random.normal(100, 10, 200)
collectn_2 = np.random.normal(80, 30, 200)
collectn_3 = np.random.normal(90, 20, 200)
collectn_4 = np.random.normal(70, 25, 200)

The pst of arrays that we created above is the only required input for creating the boxplot. Using the data_to_plot pne of code, we can create the boxplot with the following code −

fig = plt.figure()
# Create an axes instance
ax = fig.add_axes([0,0,1,1])
# Create the boxplot
bp = ax.boxplot(data_to_plot)
plt.show()

The above pne of code will generate the following output −

Line of Code Advertisements