它是使用以下代码生成的:
import matplotlib.pyplot as plt
import numpy as num
treshold_file='false_alarms.txt'
with open(treshold_file, 'r') as f2:
lines = f2.readlines()
data = [line.split() for line in lines]
data1 = num.array(data)
data2= data1.astype(float)
plt.hist((data2), alpha=0.4,bins=[100,110,120,130, 140,150,160,180,200,250,300,350,400])
plt.xlabel("treshold")
plt.ylabel("Frequency")
我想为每个bin绘制大于或等于给定阈值的值数量。
对于bin 100,我想绘制样本数量> 100,依此类推。
bar
构建必要的数据后,我将使用手动绘制:
import numpy as np
import matplotlib.pyplot as plt
# dummy data
data2 = np.random.randint(low=0,high=450,size=200)
bins = [100,110,120,130,140,150,160,180,200,250,300,350,400]
binwidths = np.diff(bincenters)
binvals = [np.sum(data2>=thresh) for thresh in bins[:-1]]
plt.figure()
plt.bar(bins[:-1],binvals,width=binwidths,alpha=0.4)
plt.xlabel('threshold')
plt.ylabel('occurences')
结果:
该数组bins
实际上ndarray
是阈值列表()。对于每个阈值,我们计算其数量data2
大于阈值的值,它们是称为的条形图的值binvals
。我们跳过最后一个索引,以在输出中获取正确的尺寸。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句