wosker4yan
wosker4yan

Reputation: 313

How to fill in the interpolated values inside the array so that they are equidistant

I have used this example How to generate equispaced interpolating values to make the equidistant points in the data and got the following plot

enter image description here

I have taken the values of this scatter and interpolated them but when I check it the difference between the points is not the same. How can I make it so the difference between the points are the same.

old_indices_yn = np.arange(0,len(yn))
new_length = 50
new_indices_yn = np.linspace(0,len(yn)-1,new_length)
spl = UnivariateSpline(old_indices_yn,yn,k=3,s=0)
new_array_yn = spl(new_indices_yn)

old_indices_xn = np.arange(0,len(xn))
new_length = 50
new_indices_xn = np.linspace(0,len(xn)-1,new_length)
spl = UnivariateSpline(old_indices_xn,xn,k=3,s=0)
new_array_xn = spl(new_indices_xn)

plt.scatter(new_array_xn,new_array_yn, s=8)
plt.scatter(x,y,s=8)

Here is the plot I get from the interpolation. enter image description here

Upvotes: 0

Views: 535

Answers (1)

wosker4yan
wosker4yan

Reputation: 313

x=Field.columns.astype('float64')
y=Field.index.to_numpy() 

plt.figure(0)
plt.scatter(x,y,s=0.5)
plt.title("points are not equidistant")

z=Field.to_numpy() 
X,Y = np.meshgrid(x, y)
 
plt.figure(1)
plt.plot(X,Y)
plt.title('grid before')

plt.figure(2)
plt.contourf(X, Y, z, alpha = 1, cmap=plt.cm.inferno) #change of scale
plt.title('field before')


x1 = np.linspace(min(x),max(x),128);
y1 = np.linspace(min(y),max(y),128);

plt.figure(3)
plt.scatter(x1,y1,s=0.5)
plt.title("scatter of equidistant points")

X11,Y11 = np.meshgrid(x1, x1)
scale = (max(y)-min(y)/(max(x)-min(x)));#scale because x and y differ

plt.figure(4)
plt.plot(X11,Y11)
plt.title('new gird')



zi1 = interpolate.griddata((x*scale,y),z,(x1*scale,y1), method='nearest')
plt.figure(5)
plt.contourf(X11, Y11, zi1, alpha = 1, cmap=plt.cm.inferno) #change of scale
plt.title('Interpolated fied nearest with scale')

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 1

Related Questions