如何将一组等距平行线拟合到数据网格中

问题描述 投票:0回答:1

我想使用最小二乘最小化技术将一组等距的平行线拟合到数据网格。我能够使独立的平行线适合我的数据。但是,不出所料,拟合结果的y截距间隔不相等。

这是我到目前为止的内容:

import numpy as np
import matplotlib.pyplot as plt

x = np.array([1, 2, 3])
y1 = np.array([60.8, 60.5, 60.5])
y2 = np.array([377.6, 376.8, 377.7])
y3 = np.array([695.4, 695.8, 695.5])

fit_1 = np.polyfit(x,y1,0)
fit_2 = np.polyfit(x,y2,0)
fit_3 = np.polyfit(x,y3,0)

plt.plot(x,y1,'*',x,y2,'*',x,y3,'*')
for line in fit_1,fit_2,fit_3:
    plt.axhline(line, color='r')

平行线适合水平数据:

“平行线适合于水平数据”“>

有人对我如何将每条平行线之间的间距限制为相等有任何想法吗?

谢谢!

我想使用最小二乘最小化技术将一组等距的平行线拟合到数据网格。我能够使独立的平行线适合我的数据。但是,按预期方式,...

python numpy least-squares data-fitting scipy-optimize
1个回答
0
投票

如果您按照以下方式转换数据,则可以为此绘制一条线

© www.soinside.com 2019 - 2024. All rights reserved.