Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 how to get x values based on y-axis values from curvefit function
#1
Hi,

I have fitted a function for extrapolation and now I would like to get the x value when y is of a certain value. How do I get this?

def func(x, b1, b2):
    return b1*np.exp(-b2*(x))

x = np.array([47,77,103,129,152,177,207,234,255,282,311,337,358,382,416,440,463,490,512,535,566,573])
y = np.array([0.904996,0.946489,0.931208,0.930137,0.915004,0.92138,0.911744,0.908241,0.894834,0.895659,0.897973,0.885373,0.895916,0.883586,0.880162,0.857255,0.872408,0.87055,0.855421,0.854406,0.852419,0.853073])

popt, pcov = curve_fit(func, x, y, p0=[0.1,0.1])

plt.plot(x, y, 'x')
xx = np.linspace(0, 2000, 100)
yy = func(xx, *popt)
plt.plot(xx, yy, lw=1)


Thanks.
Quote
#2
This problem can be solved in many ways, e.g. consider the following:

from scipy.optimize import root_scalar
root_scalar(lambda x: func(x, *popt) - your_y_value, bracket=[0, 10000], method='bisect')
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to copy a .csv worksheet into a .xlsx file without the number values turning into YoshikageKira 7 142 Mar-28-2020, 10:38 AM
Last Post: buran
  Counter to keep track how many times values in a list appear in each row in a column chief 0 68 Mar-24-2020, 08:14 PM
Last Post: chief
  How to obtain values under All when the margins of pivot_table is set to True? new_to_python 0 110 Mar-03-2020, 02:54 PM
Last Post: new_to_python
  replace nan values by mean group by date.year, date.month wissam1974 5 1,548 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Identifying consecutive masked values in a 3D data array chai0404 12 717 Feb-01-2020, 12:59 PM
Last Post: perfringo
  Graph that shows predicted vs true values donnertrud 1 122 Jan-28-2020, 07:47 PM
Last Post: jefsummers
  values spiral out of control Tinfoil 0 112 Jan-16-2020, 03:43 PM
Last Post: Tinfoil
  Pandas copying wrong values vmarg 2 166 Jan-06-2020, 09:45 AM
Last Post: vmarg
  ValueError: The condensed distance matrix must contain only finite values. kisumsam 1 350 Dec-29-2019, 10:14 AM
Last Post: Larz60+
  huge and weird values after applying some calculations karlito 2 253 Dec-13-2019, 08:32 AM
Last Post: karlito

Forum Jump:


Users browsing this thread: 1 Guest(s)