Python | Horizontal Box Plot

Horizontal Box Plot in Python: In this tutorial, we will learn how to create horizontal box plot using matplotlib? By Anuj Singh Last updated : August 18, 2023

Horizontal Box Plot Using Matplotlib

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

Example

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

Python | Horizontal Box Plot

Python program 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!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.