Python Matplotlib - How to Create Box Plot in Python

avatar

In this post, we take a look at How to Create Box Plot in Python using Matplotlib. Previously we looked at How to Create 2D Historgram Plot in Python. That plot was specific to the 2D plot and it kind of was good for the design and also presenting the data the right way. So in that context as you can see this particular plot is really good for those who like the population charts or the charts specific to the distributed values over a period of time.

Box plot on the other hands you would find that they can be also a good option for distribution specific data plots. You may find plenty of datasets making use of the box plot for this type of the purpose. I have made use of those box plots in some datasets that would make things a bit better for the plotting of the certain datasets too. I guess for those who like such certain plots should use them.

You can run the code here using the Jupyter notebook. And same can be run through the

And I have created a video to give you an overview on How to Create Box Plot in Python. You should give this below video a loook.



First thing make sure to have a python setup installed on your OS. You can verify the python setup with below command.

python --version

Next step make sure to setup the following libraries.

pip install numpy, jupyter matplotlib

Now that you have the matplotlib, we are going to get the test data for our example. But before that let's get the libraries referenced here first.

import matplotlib.pyplot as plt
import numpy as np

Now if you can get the test data done that would be super specific as well.

np.random.seed(10)
data = np.random.normal(100, 20, 200)

Now lets put entire code together to get our plot.

import matplotlib.pyplot as plt
import numpy as np
np.random.seed(10)
data = np.random.normal(100, 20, 200)
fig = plt.figure(figsize =(10, 7))
plt.boxplot(data)
plt.show()

You can even check the below image for the reference code.

Now once you have the code done, next step is to execute the same. So we make use of the code in example.py file and we are going to be executing the same.

python example.py

Now that should show you the output on the desktop. You can see the box plot in the there. It would be pretty cool for you to see how it can be changed and modified in variety of ways now.

Make sure to experiment with the configurations like orientation of the box plot. You can also make sure to add the legend for the dataset. Another option is to make sure to add the changes in colors too. So that's another feature set for you to explore. I'd experiment with the data sets as they come in specifically for this type of the data in the box xplot. But overall we are kind of done with the plot and things have settled in as well. I'd recommend checking out the further config values through docs.

Make sure to like, share and subscribe my content on youtube. If you check the above video that would give you a link to the channel. You can comment below the video too that would help with my algorithm. I guess that would make things be much quicker for my reach to move ahead. I have a lot of content but not able to reach people these days and so your help to push my content is much appreciated. Slow and steady as they say. If you have any tutorial suggestion, you can comment below as well. :)

If you happen to like this content, do give me feedback over there and that would help me improve my efforts in near future.



0
0
0.000
2 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support. 
 

0
0
0.000
avatar

Congratulations @devpress! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You have been a buzzy bee and published a post every day of the week.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out our last posts:

Hive Power Up Day - November 1st 2023
0
0
0.000