title: implicit curve fitting using scattered data
body: <p>I have two arrays - <code>x</code> and <code>y</code> - which corresponds to coordinates <code>(x,y)</code> in a cartesian plane. For example, with the <code>scatter</code> function (<code>plt.scatter(x,y)</code>) from <code>matplotlib</code> (so far, I'm trying to solve my problem using Python), I get the following result:  <a href="https://i.stack.imgur.com/1O8nu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1O8nu.png" alt=""></a></p>
  
  <p>What I really need is to get an implicit function <code>f(x,y)</code> from this data, or at least coefficients from an approximate function <code>f(x,y)</code> .  So far, I tried to use the <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow noreferrer"><code>curve_fit</code>function from <code>scipy.optimize</code></a> as suggested <a href="https://stackoverflow.com/questions/10857948/use-of-curve-fit-to-fit-data">here</a>, but I've got the following error message:</p>
  
  <pre><code>OptimizeWarning: Covariance of the parameters could not be estimated category=OptimizeWarning)
  </code></pre>
  
  <p>That is my code so far:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from scipy.optimize import curve_fit
  import scipy as sy
  import pylab as plb 
  
  def func(x, a, b, c):
      return a*x**b + c
  def main():
      file = open('firstcurve.out')
      lines = file.read().split('\n')
      file.close()
      x = []
      y = []
      for item in lines:
          if len(item) &gt; 0:
              numbers = item.split(",")
              x = x + [float(numbers[0])]
              y = y + [float(numbers[1])]
  
      p0 = sy.array([1,1,1])
      coeffs, matcov = curve_fit(func, x, y, p0)
      yaj = func(x, coeffs[0], coeffs[1], coeffs[2])
      plt.plot(x,yaj,'r-')
      plt.show()
  main()
  </code></pre>
  
  <p>Any help or suggestions are really appreciated! </p>
  
  <p>PS: I'm trying to do it in Python, but MatLab is also an option in case there is any tool that does what I need to. I tried to use the <a href="https://www.mathworks.com/matlabcentral/fileexchange/24443-slm-shape-language-modeling" rel="nofollow noreferrer">SLM ToolKit</a> but it didn't work as well.</p>