Package: complex-curve-fit-gui
InstallationYou can install thecomplex-curve-fit-guifromPyPi:pip install complex-curve-fit-guiThe GUI is supported on Python 3.7 and above.Note: onlycomplex-curve-fit-guiis 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 PyQt5 lmfit sympyUsingconda(required for M1 Mac):conda install numpy scipy matplotlib sympy qtpy pyqt && conda install -c conda-forge lmfitGetting StartedIf on MacOS M1 a conda environment will be neededimport the gui:from complex_curve_fit_gui import curve_fit_guidefine 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])Call curve_fit_gui:Set first parameter to None to be able to select predefined functionsFor example:curve_fit_gui(None,xdata,ydata)Optionally disable gui and immediately get fit results as tuple (popt, pcov, result) where popt is an array of the best-fit parameters, pcov is an array of the confidence intervals, and result is an lmfit ModelResult object.Model Resultcurve_fit_gui(function,xdata,ydata, showgui=False)Open Multiple WindowsAppending&to the end of the command used to run program will give access to current terminal, allowing for another window to be openned. Ex:python3 curve.py&Plot multiple dataset on single windowUse the keyword argumentaddand format argument as an array of tuples i.e[(np.array, np.array, string)]where the first index is xdata, the next in y-data, and the last is a label for the datacurve_fit_gui function:This starts up the GUI. The call signature iscurve_fit_gui(f,xdata,ydata,xerr=None -> [optional],yerr=None -> [optional],p0=None  -> [optional],xlabel="x-axis" -> [optional],ylabel="y-axis" -> [optional],absolute_sigma=False -> [optional],jac=None -> [optional],showgui=True -> [optional],**kwargs, -> [optional])f : callable
the fit function which if set to None, gives option of selection predefined fit functionsxdata : 1-D numpy array
x-coordinates of the dataydata : 1-D numpy array
y-coordinates of the datayerr : 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 plottitle  : string, optional
data plot titlep0 : array-like, optional
initial values for fit parameters, if not specified 1 is used for each parameter, if specified length must be >= number of fit parameters else program crashes upon fitmethod : string, optional
desired fit method for lmfit model, default is "least squares"showgui : boolean, optional (default=True)
if True, the gui is shown, otherwise notabsolute_sigma : boolean, optional
see doc-string scipy.optimize.curve_fit()add : array of tuple, optional
add additional data sets, requires format[(np.array, np.array, string)]which implies[(x_data, y_data, label)]. Multiple datasets can be placed in the array, and method is selectable within guikwargs
keyword arguments for compatibility (e.g. you can use sigma to specify the error in y)Return DataThe curve fit function returns a tuple with three elements.
1. Array containing the fit parameters
2. Array containing the standard error (+/-)
3. lmfit Model_Result object pertaining to the best fit, reference here:https://lmfit.github.io/lmfit-py/model.html#the-modelresult-classUser defined functionsTo make a user defined function create a function and pass to curve_fit_gui as f. For example:deflinear(x,a,b,c):'''y = a * x + b'''returny=a*x+bcurve_fit_gui(linear,xdata,ydata)User defined complex functionsWhen defining a complex function add thecomplex=Truekeyword argument and use1jin the equation. For example for Euler's equation e^(ix)cs:return a * (np.exp(1j * (x)))Customizing Data PlotThe plots are customizable from inside the gui and also from thecurve_fit_guifunction call by using keyword arguments or kwargs. The options available from a matplotlib plot are also available for the main data plot
For example:curve_fit_gui(None, xdata, ydata, markerfacecolor="None", linestyle="-"For a list of optional keyword arguments visit the matplotlib documentation on this page under the list of available Line2D properties:matplotlib.pyplot.plotNote: Use full names i.e. linewidth not lwIn addition, title can be set using title keyword argument i.ecurve_fit_gui(...,...,...,title="More Data")Customizing Fitline:Options for customizing fitline inlclude color, linestyle, and thickness. The values are the same from matplotlib, however the argument is preceded with fitline_. For examplecurve_fit_gui(None, xdata, ydata, fitline_color="red", fitline_linestle="-"). The possible customizations for fitline are:
- fitline_color
- fitline_linestyle: supported values are '-', '--', '-.', ':', 'None', ' ', '', 'solid', 'dashed', 'dashdot', 'dotted'
- fitline_label
- fitline_linewidthGUI 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:Model settings:Here you can enter inital values for the fitparameters. By ticking the checkboxfixyou can set a parameter to fixed:e.g. the parameter is not optimised 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 a tuple of best-fit parameters, confidence interval, and Model Result object from lmfit.Model ResultToolbar:This is the standard matplotlib toolbar to adjust some plot properties and provides zoom/pan and save options.CustomizeChange visual features of the plot such as marker type or color and axis titlesPan and ZoomShift and zoom on plotLeft and RightUndo and redo actions for shift and zoomHomeReturn to original plot viewFitTextbox: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.SELECT DATAAllows user to switch between plotted dataset and desired fit modelTOGGLE Residualshow/hide residual plot