Not expected result received with scipy's curve_fit
<p>I was trying to do multivariate logarithmic regression on my data with scipy curve_fit and as a result expect to get a line, but get a curve. 
Here is the code I used : </p>

<pre><code>Quercetin=[23,195,6,262,272,158,79,65,136,198]
Naringenin=[11,4,8,6,6,7,6,9,7,9]
Rutin=[178,165,93,239,202,3325,4427,7607,3499,1762]
TEAC=[23,189,37,265,290,267,362,388,364,321]

import matplotlib.pyplot as plt
import scipy
from scipy.optimize import curve_fit
import numpy as np
def func(x, a, b, c, d,e):
    m=np.log(a*x[0]+b*x[1]+c*x[2])
    return d*(m)+e
x=scipy.array([Quercetin, Naringenin,Rutin])
y=scipy.array(TEAC)
popt, pcov = curve_fit(func, x ,y)
print (popt)

plt.plot(func(x,*popt),y,'ro-')
plt.show()
</code></pre>

<p>And I get this result:
<a href="http://i.stack.imgur.com/6RbYt.png" rel="nofollow"><img src="http://i.stack.imgur.com/6RbYt.png" alt="enter image description here"></a></p>

<p>while I want to get something like this :</p>

<p><a href="http://i.stack.imgur.com/RSbe3.png" rel="nofollow"><img src="http://i.stack.imgur.com/RSbe3.png" alt="enter image description here"></a></p>

<p>Could anyone please give me a hint on what I am doing wrong?
If this matters I use Python 3.5 from Anaconda on Windows 10. </p>

<p>(I'm assuming that the question is really about plotting). 
You are asking <code>matplotlib</code> to plot red dots (<code>'ro'</code>) connected by straight lines (<code>-</code>). Matplotlib obliges and connects them in whatever order they are given.</p>

<p>If you want to plot a line, just plot it separately:</p>

<pre><code>In [58]: yres = func(x, *popt)

In [59] plt.plot(yres, y, 'ro')
Out[59]: [&lt;matplotlib.lines.Line2D at 0x7f5c0796b828&gt;]

In [60]: plt.plot([0, 400], [0, 400], '-')
Out[60]: [&lt;matplotlib.lines.Line2D at 0x7f5c07a9c860&gt;]
</code></pre>

python scipy curve-fitting