简体   繁体   中英

Plotting resulting fitted curve with scipy

According to this , what about if I want to overplot the fitted curve over the data points? Should I define the fitting function again?

Leastsq method has lacking documentation and examples, and I have some troubles in understanding the arguments it needs.

According to that, if I define:

def optm(l, x, y):
    return skew(x, l[0], l[1], l[2]) - y

Then, is it correct to fit in the following way:

out_param = leastsq(optm, v1[:], args = (x_values, y_values), maxfev = 100000, full_output = 1)

(where v1[:] is the vector with the initial guess parameters)? And then, again, how can I plot the resulting curve?

I am still trying to understand so any suggestion is really appreciated.

I have solved in the following way: The string code reported in the question was correct. Then I saved the best-fit parameters in another vector:

p = out_param[0]

Then, I used the skew function to obtain the new (fitted) y_values:

new_y_val = skew(x_values, p[0], p[1], p[2])

And finally I can make a plot with these new vectors:

plot(time1, pl)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM