简体   繁体   English

如何在 plot 中找到给定 y 值的对应 x 值

[英]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.

相关问题 Python Matplotlib:在一个基本的plot上找到给定y值对应的x值 - Python Matplotlib: Find the corresponding x value of a given y value on a basic plot Python在绘图中找到x值到相应的max y值 - Python find x value to corresponding max y value in plot 查找给定z坐标值的相应[x,y]坐标 - Find the corresponding [x,y] coordinates for a given z coordinate value 在X轴上查找对应于Y的任意值的值,该值不包含在用于在python中绘制数据的列表中 - To find the value on X axis corresponding to an arbitrary value of Y that doesn't contain in the list used to plot the data in python Python Seaborn Distplot Y值对应于给定的X值 - Python Seaborn Distplot Y value corresponding to a given X value 如何从散点 plot 中找到最佳值 x 和 y 值? - How to find the optimal value x and y values from a scatter plot? 如何使用 Numpy 数组查找给定值的 x 和 y 坐标 - How to find the x and y coordinates of a given value using Numpy array 我应该如何找到对应于抛物线的最大或最小 y_value 的 x_value? (在 Python 中) - How should I find the x_value corresponding to the max or min y_value of a parabola? (in Python) 有没有办法在元组/列表中找到对应 y 的 x 的第一个值? - Is there a way to find the first value of x to a corresponding y in a tuple/ list? 需要帮助理解一行代码如何使用最大 y 坐标在 python 中找到相应的 X 值 - Need help understanding how a line of code is using a maximum y coordinate to find the corresponding X value in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM