×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Histogram vs Box Plot using Matplotlib

Histogram vs Box Plot in Python: In this tutorial, we will learn to compare histogram and box plot for data visualization? By Anuj Singh Last updated : August 18, 2023

Histogram Vs Box Plot using Matplotlib

Both box plot and histogram are used for data visualization and analyzing the central tendency in data. Therefore, we are comparing both so that we can find which is a good data visualization technique.

Examples

Python | Histogram vs Box Plot (1) Python | Histogram vs Box Plot (2) Python | Histogram vs Box Plot (3)

Python program for histogram vs box plot using matplotlib

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 Histogram')
plt.hist(data)
plt.ylabel('Variation')
plt.grid()

plt.figure()
plt.title('Horizontal Histogram')
plt.boxplot(data)
plt.ylabel('Variation')
plt.grid()

plt.figure()
plt.subplot(121)
plt.title('Horizontal Histogram')
plt.hist(data)
plt.ylabel('Variation')
plt.grid()

plt.subplot(122)
plt.title('Horizontal Histogram')
plt.boxplot(data)
plt.ylabel('Variation')
plt.grid()

Output:

Output is as Figure
Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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