我用plt.plot(xdata,ydata)绘制了一个图,当y坐标= 125.94937644205281 + 1 (chi-squared+1)时,我想从图中找到x坐标。我也想展示一下它的坐标。有什么方法可以做到吗?样例图
我已经尝试过定位根方法,但是需要很长时间才能找到导致chi-squared + 1的两个参数。如果matplotlib没有在图上找到特定点的任何方法,我认为我应该使用求解器。但我不知道该用哪一个解算器,也不知道如何使用解算器。
target = chisq_min + 1
def target_chisq_plus1 (gradient):
return chisq([gradient], xval, yval, yerr) - target
# Locating Roots
initials = [(a_soln, 0.0121320), (0.0122193, a_soln)] # <- Initial Boundaries for the two parameters causing chisquared + 1
tolerance = 0.01
chisquard_plus_one_solutions = []
while True:
for initial in initials:
if target_chisq_plus1(initial[0]) > 0:
xp = initial[0]
xn = initial[1]
else:
xp = initial[1]
xn = initial[0]
next_approximation = (xp + xn) / 2
if target_chisq_plus1(next_approximation) > 0:
xp = next_approximation
else:
xn = next_approximation
if abs(target_chisq_plus1(next_approximation)) < tolerance:
gradient_solutions.append((next_approximation, chisq([next_approximation], xval, yval, yerr)))
break但我似乎被困在一个无限的循环中。
发布于 2022-12-02 01:10:31
您处于无限循环中,因为您从未脱离过while True循环。break语句一次只中断一个循环。另见如何突破python中的嵌套循环?
https://stackoverflow.com/questions/74649825
复制相似问题