- 积分
- 55950
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2017-3-18 13:34 编辑
MeteoInfoLab中mipylib.numeric中增加了fitting包,用来进行曲线拟合,目前有多项式、幂函数、指数函数拟合功能。
多项式拟合:
- from mipylib.numeric import fitting
- x = linspace(0, 4*pi, 10)
- y = sin(x)
- #Plot data points
- plot(x, y, 'ro', fill=False, size=1)
- #Use polyfit to fit a 7th-degree polynomial to the points
- r = fitting.polyfit(x, y, 7)
- #Plot fitting line
- xx = linspace(0, 4*pi, 100)
- p = r[0]
- yy = fitting.polyval(p, xx)
- plot(xx, yy, '-b')
- title('Polynomial fitting example')
幂函数拟合:
- from mipylib.numeric import fitting
- fn = 'D:/Temp/ascii/PM&vis-1.txt'
- ncol = numasciicol(fn)
- nrow = numasciirow(fn)
- a = asciiread(fn,shape=(nrow,ncol))
- x=a[:,0]
- y=a[:,1]
- z=a[:,2]
- axes(tickfontsize=17)
- ls=scatter(x,y,s=8,c=z,cmap='NCV_jet',edgecolor=None,cnum=20)
- xlim(0,450)
- ylim(0,30)
- xlabel(r'$\rm{PM_{2.5}} \ (\mu g \ m^{-3})$',fontsize=17)
- ylabel(r'$\rm{Visibility (km)}$',fontname='Arial',fontsize=17)
- colorbar(ls,fontsize=17,label='RH(%)')
- #Pow law fitting
- a,b,r,f = fitting.powerfit(x, y, func=True)
- #Plot fitting line
- xx = linspace(x.min(), x.max(), 100)
- #yy = a*pow(xx, b)
- yy = fitting.predict(f, xx)
- plot(xx, yy, '-b', linewidth=2)
- text(250, 20, r'$y = ' + '%.4f' % a + 'x^{%.4f' % b + '}$', fontsize=16)
- text(250, 18, r'$r^2=%.4f' % r + '$', fontsize=16)
|
|