删除直方图中阈值以上的数据 [英] Remove data above threshold in histogram
本文介绍了删除直方图中阈值以上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将数据显示在带有以下代码的直方图中:角度=数据[列[3]]
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.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-')
显示以下内容:
我正在寻找一个将删除行上方所有数据的函数.或者说,每个bin中的数据不能超过200个.
I'm looking for a function that will delete all data above the line. or in other words, the data in each bin cannot exceed 200.
有没有一种巧妙的方法来做到这一点?
Is there a neat way of doing this?
推荐答案
您可以选择低于特定阈值的值来屏蔽数组.例如:
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()
哪个给:
这篇关于删除直方图中阈值以上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文