title: How to do exponential curve fit for a set of data using python?
body: <p>For the life of me, I can't figure out how to do an exponential curve fit for this set of data. I've looked at quite a number of other posts and tried doing it other ways but in the end, I could never get it to work. Please try to simplify things as much as possible because I have very little experience with coding.</p>
  
  <pre><code>def func(x, a, b):
      return a*np.exp(-b*x)
  
  x = arrx
  y = arry
  popt, pcov = curve_fit(func, x, y)
  xFit = np.arange(0.0, len(x), 1)
  plt.plot(xFit, func(xFit, *popt), 'r', label='fit params: a=%5.3f, b=%5.3f' % tuple(popt))
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Ik2tx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ik2tx.png" alt="The graph I get from the following code is shown below"></a></p>
  
  <p>The red line should be my curve fit but I'm very inexperienced so I'm not sure what's wrong.</p>