Multiple Box Plot in Python using Matplotlib

In this example, we are going to plot multiple box plots in a single figure?
Submitted by Anuj Singh, on August 08, 2020

Following example illustrates the implementation of our desired plot.

Multiple Box Plot in Python (1)

Multiple Box Plot in Python (2)

Python code for multiple box plot using matplotlib

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(562201)
all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)]
labels = ['x1', 'x2', 'x3']

#MultipleBoxplot
plt.boxplot(all_data, vert=True, patch_artist=True, labels=labels) 
plt.ylabel('observed value')
plt.title('Multiple Box Plot : Vertical Version')
plt.show()

plt.boxplot(all_data, vert=False, patch_artist=True, labels=labels) 
plt.ylabel('observed value')
plt.title('Multiple Box Plot : Horizontal Version')  

Output:

Output is as Figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





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


© https://www.includehelp.com some rights reserved.