import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
def func(x, a, b, c):
return a * np.exp(-b * x) + c
x = [333,500,1000,2000,5000,10000]
y = [195.3267, 233.0235, 264.5914,294.8728, 328.3523,345.4688]
popt, pcov = curve_fit(func, x, y)
plt.figure()
plt.plot(x, y, 'ko', label="Original Noised Data")
plt.plot(x, func(x, *popt), 'r-', label="Fitted Curve")
plt.legend()
plt.show()
Error: C:\Users\Aidan\Anaconda3\lib\site-packages\scipy\optimize\minpack.py:794: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () 14 plt.figure() 15 plt.plot(x, y, 'ko', label="Original Noised Data") ---> 16 plt.plot(x, func(x, *popt), 'r-', label="Fitted Curve") 17 plt.legend() 18 plt.show()
in func(x, a, b, c) 4 5 def func(x, a, b, c): ----> 6 return a * np.exp(-b * x) + c 7 8 x = [333,500,1000,2000,5000,10000]
TypeError: 'numpy.float64' object cannot be interpreted as an integer
For some reason I am not able to get a curve fit based on my data. I am following the exponential example from here: How to do exponential and logarithmic curve fitting in Python? I found only polynomial fitting
But I am using an two arrays rather than made up random data. I am new to python!