如何为同X值数据集拟合曲线并适配不同长度X-Y数据对
曲线拟合需求与现有代码
我有材料实验室测试得到的多组曲线数据,每组数据长度各不相同,想要为这些数据拟合曲线。目前先从X值相同、长度一致的y1、y2、y3数据集入手,已编写如下Python代码:
import numpy as np import matplotlib.pyplot as plt def my_function(x,y): curve = np.polyfit(x, y, 4) poly = np.poly1d(curve) new_x = np.arange(x[0],x[-1],1) new_y= poly(new_x) plt.plot(new_x, new_y) plt.scatter(x, y) print(poly) x = [0, 5.25, 10.5, 21, 31.5, 42, 52.5, 63, 73.5, 84, 94.5, 99.75, 105] y1=[0.2535,0.3552,0.456,0.489,0.5265,0.58384,1.87616,2.87328,2.55184,2.66992,2.8208,3.09632,3.51616] y2=[0.116112,0.425088,0.582528,0.70192,1.07584,2.41408,3.75232,4.61824,2.55184,2.66992,2.8208,3.09632,3.51616] y3=[0.389664,1.166368,1.60392,2.05984,2.788,4.02784,5.0184,5.60224,2.55184,2.66992,2.8208,3.09632,3.51616] ylist = [ y1, y2, y3] for y in ylist: my_function(x,y)
我的最终目标是实现对不同长度X-Y数据对的曲线拟合,期望效果如附图所示。
内容的提问来源于stack exchange,提问作者nima farhadi
相关产品推荐
相关产品推荐

