Least Square Method, Curve Fitting, Python, Residual, Data.
plt.plot(xdata1, func(xdata1, *popt), 'r-', label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt)) # Calculate the residuals residuals1 = ydata1 - func(xdata1, *popt) # Plot the residuals plt.scatter(xdata1, residuals1) plt.axhline(0, color='red', linestyle='--') plt.xlabel('x')