curvefitgui
is a graphical interface to the non-linear curvefit function scipy.optimise.curve_fit API reference of the scipy.optimize package. Currently, only the Levenberg-Marquard optimizer is supported. The GUI is based on PyQt5.
You can install the curvefitgui
form PyPi:
pip install curvefitgui
The GUI is supported on Python 3.7 and above.
Note: only curvefitgui
is 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:
Using pip
:
pip install numpy scipy matplotlib PyQt5
Using conda
:
conda install numpy scipy matplotlib qtpy pyqt
A minimum example to use curvefitgui.curve_fit_gui
is:
from curvefitgui import curve_fit_gui
import numpy as np
# define a function for fitting
def f(x, a, b):
'''
Linear fit
function: y = ax + b
a: slope
b: intercept
'''
return a * x + b
# define x and y data as 1 dimensional numpy arrays of equal length
xdata = np.array([1, 2, 3, 4, 5])
ydata = np.array([-3.5, -2.4, -1, 0.5, 1.8])
# execute the function
curve_fit_gui(f, xdata, ydata)
popt, 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_gui
accepts the following arguments:
f
: callable
function that defines the fitfunction. The first argument of f
should 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_gui
accepts 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**2xerr
: 1-D numpy array, optional (default:None)
error in x-values. For plotting errorbars only and ignored during fitting xlabel
: 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 parameter showgui
: 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)popt
: The values of the fitparameters that minimised the squared residuals if a succesful fit was performed, else None.pcov
: The estimated covariance of popt.
(see also: scipy.optimise.curve_fit API reference)Once the gui
is executed the following window is visible. An explanation of the different controls is described below the figure.
residual = ydata - f(xdata, *fitparameters)
fix
you can set a parameter to fixed:e.g. the parameter is not optmised during the fit.yerr
you can use the dropdownbox to set how the error data is treated:
absolute_sigma = False
.absolute_sigma = True
.f
that is passed to the curvefitgui
function.popt
and pcov
.