Python中利用guiqwt进行曲线数据拟合

Python中guiqwt是和MatPlotLib一样优秀的2D绘图库,基于PyQt库,

里面有进行曲线数据拟合的专门工具guifit.

guifit用起来和matlab中的cftool一样方便,

比OriginLab Pro中的曲线拟合工具.

用起来十分简单,下面是示例程序:

#-*- coding:utf-8 -*-
import numpy as np

from guiqwt.widgets.fit import FitParam, guifit

def test():
    x = np.linspace(-10, 10, 1000)
    y = np.cos(1.5*x)+np.random.rand(x.shape[0])*.2
    
    def fit(x, params):
        a, b = params
        return np.cos(b*x)+a
    
    a = FitParam("Offset", 1., 0., 2.)
    b = FitParam("Frequency", 2., 1., 10., logscale=True)
    params = [a, b]
    values = guifit(x, y, fit, params, xlabel="Time (s)", ylabel="Power (a.u.)")
    
    print values
    print [param.value for param in params]

if __name__ == "__main__":
    test()

图形界面如下:

参数可手动和自动调整.在自动拟合里面的setting,

可选择不同的拟合方法,如最小二乘法等.

你可能感兴趣的:(Python)