CFit: An online curve fitting tool
December 30, 2023
CFit is a curve fitting tool written in Python, based on the method of least squares. It comes equipped with some standard functions used in physics, and a graphical user interface built using NiceGUI. Some of the functions provided are: polynomials from linear upto quintic; periodic functions like sine and square waves; peaked functions such as Gaussian, Lorentzian, Poisson, Laplacian; and monotonic functions like exponential, power law, and logarithmic.
Under the hood, the code calls scipy.optimize.curve_fit
, but the real strength of this tool lies in the fact that by looking at the range, scale and behaviour of the data, the code automatically provides a initial guess for the parameters for curve_fit
to work with. Of course, if the user decides, they can also provide their own initial guess, which can be useful in cases where the code fails to work. The plot and residuals conveniently show how good the fit is, also there is also functionality to customize the plots.
This initially started as a passion project during the COVID-19 lockdown in 2020, partly inspired by a similar, much more basic tool used at the University of Manchester called ‘LSFR.py’ (by Abie Marshall, 2016). The code was written in a few days, but the GUI took a couple weeks to get right (with a v2.0 built in 2023). The code is available on GitHub, and the web app is hosted on Render. The code can also be used without the GUI if needed!