Box Plot in Python using Matplotlib
What is Box Plot?
A Box plot is a way to visualize the distribution of the data by using a box and some vertical lines. It is known as the whisker plot. The data can be distributed between five key ranges, which are as follows:
Here IQR represents the InterQuartile Range which starts from the first quartile (Q1) and ends at the third quartile (Q3).
Box Plot visualization
In the box plot, those points which are out of range are called outliers. We can create the box plot of the data to determine the following:
The range of the data from minimum to maximum is called the whisker limit. In Python, we will use the matplotlib module's pyplot module, which has an inbuilt function named boxplot() which can create the box plot of any data set.
In the boxplot() function, we have a lot of attributes which can be used to create a more attractive and amazing box plot of the data set.
We will create the random data set of the numpy array and create the box plot.
In the above code, first of all, we have imported the numpy and matplotlib libraries in the code. Then we created the random dataset and plotted the box plot using the boxplot() function.
We can create multiple box plots simultaneously in the same file.
In the above code, we have four data sets using random methods of numpy. Then we have created the list of the four data sets and use this inside boxplot() function.
We can use some attributes of the boxplot() function to customize the plot.
In the above code, we have created the four datasets using random functions and set them in a list. Now we have set the different colors for each box plot using the list of colors and using the function set_facecolor().
We have set the line width of each box plot and also set the labels for each box plot. We have set attribute vert =0, which means all the plots will be in horizontal mode.
Next TopicBox-Cox Transformation in Python
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week