I am having a problem when I try to find best fit to my data. Using scipy.optimize.curve_fit to create best fit. My data and code is:
EDIT You can download the data file from here. data is,
a b b2
55478 1.07E+43 54395.93833
56333 1.63E+43 54380.01385
57540 2.57E+43 52393.31605
61866 7.32E+43 52212.22838 52212.22838
code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import fit
import glob
import os
from scipy.optimize import curve_fit
import matplotlib.patches as patches
pf = pd.read_csv('/home/imhotep/Desktop/lala.csv', sep=',', encoding ='utf-8')
a1= pf['a'].max()
b1 = pf['b2'].max()
npoc=100
x = np.linspace((b1), (pf['b'].max()),npoc)
yy = np.linspace((pf['a'].min()), (pf['a'].max()), npoc)
fig = plt.figure()
ax4 = fig.add_subplot(111)
def h(x,k):
return a1* (((x-(b1))/(k))**(-(5./3.)))
popt,pcov = curve_fit(h,x,yy)
print 'POPT,', popt,'PCOV',pcov
y_fi1 = h(x, *popt)
ax4.plot(x, y_fi1, label='fit', ls='-', color='blue')
ax4.plot(pf['b'], pf['a'], ls='None', color='blue', marker='o')
plt.show()
like that. When I run the code I'm getting that fit:
But, it should be roughly like that:
Can anyone tell me where I go wrong? I am beginner about curve fitting.