import pandas as pd
df = pd.DataFrame({'X' : X, 'Y' : Y}) #we build a dataframe from the data
data_cut = pd.cut(df.X,bins) #we cut the data following the bins
grp = df.groupby(by = data_cut) #we group the data by the cut
ret = grp.aggregate(np.median) #we produce an aggregate representation (median) of each bin
#plotting
plt.scatter(df.X,df.Y,color='k',alpha=.2,s=2)
plt.plot(ret.X,ret.Y,'r--',lw=4,alpha=.8)
plt.show()
这个问题也可以通过python pandas(Python数据分析库)有效地解决,它提供了本地的数据切割和分析方法。在
想想这个
(我从他的例子中借用了}的例子,向@Hooked致敬)
X
和{备注:此处红色曲线的x值为按箱的x-中间值(可以使用箱子的中点)。在
我会用^{} 为你做垃圾箱分类。通过这种方式,您可以轻松地应用任何函数并设置您感兴趣的范围。在
作为方法多功能性的一个例子,让我们添加由每个箱子的标准偏差给出的误差条:
^{pr2}$您可以基于
numpy.median()
创建一个函数,该函数将计算给定间隔的中值:然后将此函数用于所需的时间间隔:
^{pr2}$相关问题 更多 >
编程相关推荐