Python 删除直方图中高于阈值的数据

Python 删除直方图中高于阈值的数据,python,numpy,matplotlib,Python,Numpy,Matplotlib,我在HitGram中显示数据,代码如下: 角度=数据[列[3]] num_bins = 23 avg_samples_per_bin = 200 # len(data['steering'])/num_bins hist, bins = np.histogram(data['steering'], num_bins) width = 0.7 * (bins[1] - bins[0]) center = (bins[:-1] + bins[1:]) * 0.5 plt.bar(center, h

我在HitGram中显示数据,代码如下: 角度=数据[列[3]]

num_bins = 23
avg_samples_per_bin = 200

# len(data['steering'])/num_bins
hist, bins = np.histogram(data['steering'], num_bins)
width = 0.7 * (bins[1] - bins[0])
center = (bins[:-1] + bins[1:]) * 0.5
plt.bar(center, hist, align='center', width=width)
plt.plot((np.min(angles), np.max(angles)), (avg_samples_per_bin, avg_samples_per_bin), 'k-')
显示以下内容:

我正在寻找一个功能,将删除以上的行所有数据。或者换句话说,每个箱子中的数据不能超过200


有没有一种简洁的方法可以做到这一点?

您可以屏蔽数组,选择低于某个阈值的值。例如:

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()
将numpy导入为np
将matplotlib.pyplot作为plt导入
图(ax1,ax2)=plt.子批次(1,2)
ax1.设置标题(“某些数据”)
ax2.设置标题(“屏蔽数据<80”)
np.随机种子(10)
数据=np.random.randn(1000)
数量=23
平均每箱样本数=200
hist,bins=np.直方图(数据,num_bins)
宽度=0.7*(料仓[1]-料仓[0])
中心=(垃圾箱[:-1]+垃圾箱[1:])*0.5
ax1.条形图(中心、历史、对齐=中心、宽度=宽度)
阈值=80
掩码=历史<阈值
新中心=中心[遮罩]
新历史=历史[掩码]
ax2.条(新中心,新历史,对齐=“中心”,宽度=宽度)
plt.show()
其中: