Python | Horizontal Box Plot

In this article, we are going to learn how to create horizontal box plot using matplotlib?
Submitted by Anuj Singh, on August 08, 2020

There is an inbuilt function defined for our desired operation i.e. matplotlib.pyplot.box(data, vert=False).

Following is an example illustrating a normal box and notched box plot.

Python | Horizontal Box Plot

Python code for horizontal box plot

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('Horizontal Box Plot')
plt.boxplot(data, notch=False, vert=False)
plt.ylabel('Variation')
plt.show()

plt.figure()
plt.title('Horizontal Notched Box Plot')
plt.boxplot(data, notch=True, vert=False)
plt.ylabel('Variation')
plt.show()

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.