matplotlib组合起点和终点

2024-04-26 10:19:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试拟合一个数据集。当我绘制最终参数时,拟合看起来像照片中的lilke。我不想要结合x轴起点和终点的直线。我该怎么做? 适合的样子:http://i.stack.imgur.com/heI8d.jpg

def solvePlot(self):

    def massFunc(t, a, b, c):
        return a*(t*t)+b*t+c

        #ravel function turns the list to 1dimension for use to fitting.
    self.x = self.Tepoch.ravel()
    self.y = self.TOC.ravel()

    p0 = [2, 0.2, 28, 6.6]
    fitParams, fitCovariances = curve_fit(massFunc, self.x, self.y, p0)

    print fitParams
    print fitCovariances

    sigma = [fitCovariances[0,0], fitCovariances[1,1], fitCovariances[2,2] ]
    plt.plot(self.x, massFunc(self.x, fitParams[0], fitParams[1], fitParams[2]))
    plt.plot(self.x,self.TOC,'o')


    plt.ylabel('O-C')
    plt.xlabel('EPOCH')
    plt.show()

enter image description here


Tags: to数据self参数plotdef绘制plt