Skip to content
Advertisement

Pulling x-values of spline integer y-values?

I have the given sample data and interpolated spline:

JavaScript

enter image description here

I would like to pull the x values that correspond to the integer y values of the spline, but am not sure how to do this. I assume I will be using np.where() and have tried (to no avail):

JavaScript

Advertisement

Answer

You could use the find_roots function from this post to find the exact interpolated x-values:

JavaScript

example plot

PS: with much less points for the x’s, e.g. xs = np.linspace(min(x), max(x), 50), the curve would look a bit bumpy, and the interpolation would be slightly different:

less points

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement