Skip to content Skip to sidebar Skip to footer

Remove Data Above Threshold In Histogram

I have data displayed in a hitogram with the following code: angles = data[columns[3]] num_bins = 23 avg_samples_per_bin = 200 # len(data['steering'])/num_bins hist, bins = np.his

Solution 1:

You can mask your arrays choosing values below a certain threshold. For example:

import numpy as np
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1,2)
ax1.set_title("Some data")
ax2.set_title("Masked data < 80")

np.random.seed(10)
data = np.random.randn(1000)

num_bins = 23
avg_samples_per_bin = 200

hist, bins = np.histogram(data, num_bins)
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) * 0.5
ax1.bar(center, hist, align='center', width=width)

threshold = 80
mask = hist < threshold

new_center = center[mask]
new_hist = hist[mask]

ax2.bar(new_center, new_hist, align="center", width=width)

plt.show()

Which gives:

enter image description here

Post a Comment for "Remove Data Above Threshold In Histogram"