How to generate equispaced interpolating values

前端 未结 5 537
既然无缘
既然无缘 2020-12-25 08:01

I have a list of (x,y) values that are not uniformly spaced. Here is the archive used in this question.

I am able to interpolate between the values but what I get ar

5条回答
  •  情深已故
    2020-12-25 08:37

    The following script will interpolate points with a equal step of x_max - x_min / len(x) = 0.04438

    import numpy as np
    from scipy.interpolate import interp1d
    import matplotlib.pyplot as plt
    
    data = np.loadtxt('data.txt')
    x = data[:,0]
    y = data[:,1]
    
    f = interp1d(x, y)
    x_new = np.linspace(np.min(x), np.max(x), x.shape[0])
    y_new = f(x_new)
    
    plt.plot(x,y,'o', x_new, y_new, '*r')
    plt.show()
    

    enter image description here

提交回复
热议问题