How does it work linear interpolation? It fails to predict the right value between points

My code does not work when I apply a linear interpolation between points.

Code

y= [0.1 ,0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.71]

x= [44.72, 43.4, 41.5, 39.9, 37.73, 36.1, 33.6, 31.5, 29.7, 26.4, 21.6, 16.8, 3.6, 0] 

x_new = 25

y_new = np.interp(x_new, x, y)
print(y_new)
plt.plot(x, y, "og-", x_new, y_new, "or");

Result

The red dot should be on the green line.

Expected result enter image description here

Can someone help me?


The docs say that the x values must be monotonically increasing. Yours don't.

The x-coordinate sequence is expected to be increasing, but this is not explicitly enforced. However, if the sequence xp is non-increasing, interpolation results are meaningless.

Note that, since NaN is unsortable, xp also cannot contain NaNs.

A simple check for xp being strictly increasing is:

np.all(np.diff(xp) > 0)