[英]How to find the corresponding x value for a given y value in a plot
I now have a plot and a given y value.我现在有一个 plot 和一个给定的 y 值。 I would like to find the corresponding x value for the given y value = 209. I tried to use the code here:
我想找到给定 y 值 = 209 对应的 x 值。我尝试在这里使用代码:
x = np.interp(209, ydata, xdata)
But this code doesn't work and always gives me the maximum x value which means nothing.但是这段代码不起作用,并且总是给我最大的 x 值,这意味着什么。
What should I do for finding the corresponding x value?我应该怎么做才能找到相应的 x 值? Thanks in advance for any help!
提前感谢您的帮助!
import numpy as np
def find_x(val, xdata, ydata):
x = np.where(ydata==val)
return int(xdata[x])
INPUT:输入:
xdata = np.array([1,3,5,7,9])
ydata = np.array([2,4,6,8,10])
print(find_x(4, xdata, ydata))
OUTPUT: OUTPUT:
3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.