You have several options. First, let me expand your 2D case fit = np.polyfit(x,y,4) . This means that you describe the position of the particle y as a function of x. This is normal since it will not move back to x. (That is, it can have a single y value for each x). Since the motion in space is decomposed into three independent coordinates, we can place the coordinates independently to get a 3D model:
fitxy = np.polyfit(x, y, 4) fitxz = np.polyfit(x, z, 4)
Now both y and z are a polynomial function of x. As mentioned earlier, this has the disadvantage that the particle can move monotonously along x.

A real physical particle will not behave like this. They usually bounce in all three dimensions, walking the way they like. However, there is a 4th dimension in which they never turn: time.
So add the time:
t = np.arange(data.shape[0])
Now the particle is modeled for free movement in space, as a function of time.
source share