Good call, Fathima! That works well for a grouped feel. If you’re like me and prefer sticking to the histogram approach while avoiding synthetic data, you can use the weights argument in histogram Python matplotlib. It directly represents the frequency of each bin.
Here’s how:
import matplotlib.pyplot as plt
import numpy as np
# Grouped data: intervals and counts
bins = [0, 10, 20, 30, 40]
counts = [8, 12, 24, 26]
# Data to fit the bins
data = np.array([0] * 8 + [10] * 12 + [20] * 24 + [30] * 26)
# Plotting the histogram using weights
plt.hist(data, bins=bins, edgecolor='black')
plt.show()
With this method, you use weights to directly reflect the frequencies for each bin. It’s perfect when you want your histogram to match the grouped data without synthesizing too much.