Fit erf function to data
<p>So I have hysteresis loop. I want to use the erf function to fit it with my data.</p>

<p>A portion of my loop is shown in black on the lower graph.</p>

<p>I am trying to use the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow noreferrer"><code>scipy.optimize.curve_fit</code></a> and <code>scipy.special.erf</code> function to fit the data with the following code:</p>

<pre><code>import scipy.special
import scipy.optimize

def erfunc(x,a,b):
    return mFL*scipy.special.erf((x-a)/(b*np.sqrt(2)))

params,extras = scipy.optimize.curve_fit(erfunc,x_data,y_data)

x_erf = list(range(-3000,3000,1))
y_erf = erfunc(x_erf,params[0],params[1])
</code></pre>

<p><code>mFL</code> is a constant, <code>a</code> controls the position of the erf curve and <code>b</code> the slope of the curve. (To my knowledge)</p>

<p>However, when I plot the obtained x_erf and y_erf data (in blue). I get the following fitting, which is not ideal to say the least:</p>

<p><img src="https://i.stack.imgur.com/BE4tM.png" alt="Data with erf fitting plot"></p>

<p>Is there a way i can get a proper fit?</p>

<p>Edit:
Link to data file: <a href="https://www.dropbox.com/s/o0uoieg3jkliun7/xydata.csv?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/o0uoieg3jkliun7/xydata.csv?dl=0</a>
Params[0] = 1.83289895, Params<a href="https://i.stack.imgur.com/LdUv0.png" rel="nofollow noreferrer">1</a> =  0.27837306</p>