Package: curvefitgui
A GUI for scipy's curve_fit() functioncurvefitguiis a graphical interface to the non-linear curvefit functionscipy.optimise.curve_fit API referenceof the scipy.optimize package. Currently, only the Levenberg-Marquard optimizer is supported. The GUI is based on PyQt5.InstallationYou can install thecurvefitguiformPyPi:pip install curvefitguiThe GUI is supported on Python 3.7 and above.Note: onlycurvefitguiis installed without any required dependencies. Depending on if you are using pip or conda to manage your environment you should manually install the following additional packages:Usingpip:pip install numpy scipy matplotlib PyQt5Usingconda:conda install numpy scipy matplotlib qtpy pyqtBasic usageA minimum example to usecurvefitgui.curve_fit_guiis:fromcurvefitguiimportcurve_fit_guiimportnumpyasnp# define a function for fittingdeff(x,a,b):'''Linear fitfunction: y = ax + ba: slopeb: intercept'''returna*x+b# define x and y data as 1 dimensional numpy arrays of equal lengthxdata=np.array([1,2,3,4,5])ydata=np.array([-3.5,-2.4,-1,0.5,1.8])# execute the functioncurve_fit_gui(f,xdata,ydata)Argumentspopt,pcov=curve_fit_gui(f,xdata,ydata,xerr=None,yerr=None,p0=None,xlabel='x-axis',ylabel='y-axis',absolute_sigma=False,jac=None,showgui=True,**kwargs)curve_fit_guiaccepts the following arguments:f:callable
function that defines the fitfunction. The first argument offshould be the independent variable; other arguments (at least one) are considered to be the fitparameters.xdata:1-D numpy array
x-coordinates of the dataydata:1-D numpy array
y-coordinates of the datacurve_fit_guiaccepts the following keyword
arguments:yerr:1-D numpy array, optional (default:None)
error/uncertainty in y-values used for weighted fit
with a relative weight defined as 1/yerr**2(for compatibility also the use of the keyword sigma can be used for the same)xerr:1-D numpy array, optional (default:None)
error in x-values. For plotting errorbars only and ignored during fittingxlabel:string, optional (default:'x-values')
x-axis title in the plotylabel:string, optional (default:'y-values')
y-axis title in the plotp0:array-like, optional
initial values for fit parameters, if not specified 1 is used for each parametershowgui:boolean, optional (default=True)
if True, the gui is shown, otherwise notabsolute_sigma:boolean, optional
see doc-string scipy.optimize.curve_fit()jac:callable, optional
see doc-string scipy.optimize.curve_fit()kwargs:keyword arguments for compatibility (e.g. you can use sigma to specify the error in y)Returnspopt:The values of the fitparameters that minimised the squared residuals if a succesful fit was performed, elseNone.pcov:The estimated covariance of popt.
(see also:scipy.optimise.curve_fit API reference)GUI interfaceOnce theguiis executed the following window is visible. An explanation of the different controls is described below the figure.GUI controlsData plot:A matplotlib plot that shows the data as solid dots and both y-error and x-error errorbars if provided. A fitted curve as a dashed line is shown if a fit is performed.Residual plotA matplotlib plot that shows the residuals as the difference between the measured and fitted values:residual = ydata - f(xdata, *fitparameters)Model settings:Here you can enter inital values for the fitparameters. By ticking the chcekboxfixyou can set a parameter to fixed:e.g. the parameter is not optmised during the fit.Weight settings:If error data on the y-values are passed using the keyword argumentyerryou can use the dropdownbox to set how the error data is treated:None: the error data is ignoredRelative: Use the error data for a relative weight. Corresponds to setting scipy's curve_fit() function keywordabsolute_sigma = False.Standard deviation: Treat the error data as being standard deviations. Corresponds to setting scipy's curve_fit() function keywordabsolute_sigma = True.Evaluate:Use this button to compute the model function given the current values of the parameters (set in the model settings panel)Fit:Performs the fit and updates the parameter values.Report:When a fit is performed, the results are shown here. The information on the model is actually the provided docstring of the functionfthat is passed to thecurvefitguifunction.Quit:Quits the gui and returns the fitparameterspoptandpcov.Toolbar:This is the standard matplotlib toolbar to adjust some plot properties and provides zoom/pan and save options.FitTextbox:This textbox is generated if a valid fit is performed. It can be moved by the mouse to any convenient positions in the plot.Range SelectorActivates/deactivates the range-selector. The range-selector allows to select a datarange used for fitting. Only datapoints that are within the two vertical dashed lines are considered during fitting. The lines can be moved using the mouse.