Python Forum
curve fitting matlotlib scipy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
curve fitting matlotlib scipy
#1
Hi, Could someone please advise me how I can improve the fit of my curve such that the fit goes through all my points and resembles the graph below?

from scipy.optimize import curve_fit
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

m=np.array([155.9,133.7,6.4,57.9])
t=np.array([100,150,200,250])


def exponential(x, a, b):
    return abs(a*(1-2*np.exp(-b*x)))

pars, cov = curve_fit(f=exponential, xdata=t, ydata=m, p0 = [0, 0], bounds=(-np.inf, np.inf))

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax.scatter(t, m, s=50, color='#00b3b3', label='Data')
ax.plot(t, exponential(t, *pars), linestyle='--', linewidth=2, color='black')
[Image: 2227418_orig.gif]

I'm trying to fit the solid line. I'm expecting the fit would be like the dashed line with no abs() in the fit code (although clearly that's not what the data is doing).

Many thanks. Cam
Reply


Messages In This Thread
curve fitting matlotlib scipy - by Cjstarling - Sep-10-2020, 08:51 AM
RE: curve fitting matlotlib scipy - by Cjstarling - Sep-15-2020, 01:32 PM
RE: curve fitting matlotlib scipy - by Cjstarling - Sep-15-2020, 02:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sine fitting - extra modulation Pikano 2 1,020 Jan-04-2023, 07:41 AM
Last Post: Pikano
  Fitting transfer function model to FRF data ymohammadi 0 1,693 Feb-10-2022, 10:02 AM
Last Post: ymohammadi
  Gaussian Curve Fit using Scipy ODR 83dons 1 3,856 Feb-19-2021, 10:24 PM
Last Post: Tuxedo
  Error in running the Elliott Fitting function shashisourabh 9 5,256 Nov-19-2020, 06:54 PM
Last Post: osvan
  Stretching a curve and modifying it IlikePi 0 1,956 Feb-01-2020, 03:41 PM
Last Post: IlikePi
  Fitting experimental data with differential equations : Optimization madoko 6 6,866 Jan-17-2019, 11:30 AM
Last Post: scidam
  Fitting Lognormal Data Carolyn 3 16,086 May-21-2018, 12:10 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020