I have a question.
I have plotted a graph using Matplotlib like this:
from matplotlib import pyplot
import numpy
from scipy.interpolate import spline
You could cast the array to a list:
>>> heights[list(widths).index(30)]
38.5
for the interpolated result:
s = xnew[56]
print s, heights_smooth[list(xnew).index(s)]
33.7123745819, 40.9547542163
As xnew
is an ordered list you could use the bisect module to find a closest width value for a queried width, and then find the corresponding height, in a similar fashion:
....
import bisect
pyplot.plot(xnew,heights_smooth)
#33.1222 is a queried value which does not exist in xnew.
index_of_nearest_width = bisect.bisect_left(xnew, 33.1222)
width_val = xnew[index_of_closest_width]
print width_val, heights_smooth[list(xnew).index(width_val)]
#prints the nearest width to 33.1222 then the corresponding height.
33.7123745819 40.9547542163