I'm trying to fit smooth surface to my data, but I'm not sure how to exactly do this. I thought I could use scipy RBF interpolation for it, but I'm pretty sure my method is just wrong. Anyways, my scattered data looks like this. I'm pretty new to python so this code might look completely stupid, but I tried to use scipy.interpolate.Rbf like this:
import pandas as pd
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
data = pd.read_csv('TTC.csv')
data['FZ'] = abs(data['FZ'])
data['P'] = round(data['P'] * 0.145037737730217); # kPa to Psi
data['V'] = round(data['V'])
data['IA'] = round(data['IA'])
data_sample = data[::100] #every 100th row of data
# Data for scattered points
z = data_sample['MX']
x = data_sample['FZ']
y = data_sample['SA']
data = np.c_[x, y, z]
x_grid = np.linspace(200, 1200, num=100)
y_grid = np.linspace(-10, 10, num=10)
X, Y = np.meshgrid(x_grid, y_grid, indexing='xy')
import scipy as sp
import scipy.interpolate
spline = sp.interpolate.Rbf(x, y, z, function='linear', smooth=5, episilon=5)
Z = spline(X, Y)
# plot points and fitted surface
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap='viridis_r')
ax.scatter(data[:, 0], data[:, 1], data[:, 2], c='r', s=5)
plt.xlabel('Force FZ')
plt.ylabel('Slip angle')
ax.set_zlabel('Moment MX')
ax.axis('tight')
plt.show()
End result was this. I think I understand why is this happening (the main problem is all this space between each force), but I'm not sure what other method to use. Should I try to interpolate curve for each FZ force, then fit the surface to those curves? Or could I maybe predict new points between each force that would smooth out the surface? Excuse me for my lack of knowledge in both programming and interpolation, I'm actively trying to get better at both.