Skip to content

Curve Fitter

Type the equation you want to fit, in your own variable names. The fit runs as you type and gives each parameter with its uncertainty, a plot you can style for a paper, and the Python script that reproduces both.

Write * to multiply and ^ for powers; every name that is not a variable is fitted.

Plot

Your data and the fitted curve will appear here

Add data on the left and type the equation above, or load an example.

Results

Add data and an equation. The fit runs as you type.

Python script fit.py

Runs with Python 3, numpy, scipy and matplotlib 3.6 or later (3.11 or later to match the preview): python fit.py. It prints the parameters and saves the figure.

How-to guide

How to fit an equation to your data

Paste the data, type the equation, and read the parameters; the plot and the Python script follow every change. Nothing leaves your browser.

1

Add your data

Paste columns of numbers, drop a file anywhere on the fitter or open one (.csv, .tsv, .txt, .dat). Tabs, commas, semicolons and spaces all work; with semicolons, tabs or spaces a decimal comma such as 1,5 is read as 1.5. A first row of names, such as Time (s), names the columns (time).

2

Type the equation

Write it in your own names, such as y = A*exp(-t/tau) + y0, or start from a preset. The page shows how it read the equation and points at any mistake. Check that each variable reads the right column, and add starting values, bounds or fixed values if you need them.

3

Read the results

Each parameter comes with its standard error, 95% confidence interval and relative uncertainty, and the fit with R², RMSE, AIC and BIC (reduced χ² when you give uncertainties). Warnings say in words when a parameter is poorly determined. Copy the table as text, CSV or LaTeX.

4

Style and export the plot

Set the figure size, fonts, axis labels, ticks, colours, a residual panel and the confidence band. The preview is the exported figure in miniature. Export it as PDF, PNG or SVG.

5

Take the Python script

Copy or download the script. It holds the data, or reads it from a CSV file you download beside it, fits it with curve_fit, prints the same parameters and saves the same figure.

✓

Come back later

The page remembers your equation, column choices, parameter settings and plot style in this browser, and the data too when it is under 200 kB. Reset clears it all.

How the fitting works

Your equation, read as mathematics

The equation is parsed into a tree, never run as code, so it can only compute arithmetic. 2x and 3(x + 1) multiply, ^ and ** are powers, and bx is one name (write b*x). A likely slip, such as t/2tau or a misspelt function, is pointed out with the reading the page used.

Non-linear least squares

The parameters minimise the sum of squared residuals on your data as given, with no log transform. The minimiser is Levenberg–Marquardt with exact derivatives of your equation, as SciPy’s curve_fit uses when there are no bounds. With uncertainties, each residual is divided by its σ.

Starting values found for you

Parameters the equation is linear in are solved exactly for each trial value of the others, and the rest are searched over several decades. A frequency or period inside sin or cos starts from the strongest periodicity in the data (a Lomb–Scargle periodogram), and frequencies too high for the spacing of the points to show are never tried. When a fit ends poorly the page tries again from other starting points. Any starting value, bound or fixed value you give is respected.

Uncertainties as SciPy reports them

Standard errors come from the covariance matrix, scaled by the reduced χ² unless your uncertainties are absolute, exactly as curve_fit does with absolute_sigma. The 95% intervals use Student’s t. Parameters the data cannot separate are named, with a suggestion.

A good R² is not proof of the model. Look at the residual panel: residuals that wander in a pattern rather than scatter around zero mean the equation misses something, however close R² is to 1. A model with nearly as many parameters as points will fit anything.
Method and equations

The mathematics behind the fit

The fit minimises the weighted sum of squared residuals, and every number the page reports follows scipy.optimize.curve_fit.

For a model f(x;\,\theta) with parameters \theta, the fit minimises

\chi^2(\theta)=\sum_{i=1}^{n} w_i\,\bigl(y_i-f(x_i;\theta)\bigr)^2,\qquad w_i=\frac{1}{\sigma_i^2}\ \text{or}\ 1

Levenberg–Marquardt takes steps \delta that solve, with the Jacobian J_{ij}=\partial f(x_i)/\partial\theta_j and the residuals r,

\bigl(J^{\mathsf T}WJ+\lambda D\bigr)\,\delta=J^{\mathsf T}W\,r

The covariance of the p free parameters, the standard errors and the 95% intervals are

C=s^2\bigl(J^{\mathsf T}WJ\bigr)^{-1},\qquad s^2=\frac{\chi^2}{n-p},\qquad \theta_j\pm t_{0.975,\,n-p}\sqrt{C_{jj}}

where s^2=1 when the uncertainties are absolute. The confidence band around the curve carries C through the gradient of f with respect to the parameters (the delta method).

Goodness of fit, with \bar y_w the weighted mean of y:

R^2=1-\frac{\chi^2}{\sum_i w_i(y_i-\bar y_w)^2},\qquad \bar R^2=1-(1-R^2)\,\frac{n-1}{n-p}
\mathrm{RMSE}=\sqrt{\frac{1}{n}\sum_i\bigl(y_i-\hat y_i\bigr)^2},\qquad \chi^2_\nu=\frac{\chi^2}{n-p}
\mathrm{AIC}=n\ln\frac{\chi^2}{n}+2p,\qquad \mathrm{BIC}=n\ln\frac{\chi^2}{n}+p\ln n

RMSE is unweighted and in the units of y. R^2, AIC and BIC use the weights when you give uncertainties. AIC and BIC compare models fitted to the same data: lower is better. A fixed parameter does not count in p.

References & documentation

  1. Levenberg, K. (1944). A method for the solution of certain non-linear problems in least squares. Quarterly of Applied Mathematics, 2(2), 164–168.
  2. Marquardt, D. W. (1963). An algorithm for least-squares estimation of nonlinear parameters. Journal of the Society for Industrial and Applied Mathematics, 11(2), 431–441.
  3. Moré, J. J. (1978). The Levenberg–Marquardt algorithm: implementation and theory. In Numerical Analysis, Lecture Notes in Mathematics 630, 105–116. Springer.
  4. Nielsen, H. B. (1999). Damping parameter in Marquardt’s method. Report IMM-REP-1999-05, Technical University of Denmark.
  5. Virtanen, P., Gommers, R., Oliphant, T. E., et al. (2020). SciPy 1.0: fundamental algorithms for scientific computing in Python. Nature Methods, 17, 261–272. curve_fit documentation.
  6. Heckert, N. A., Filliben, J. J., Croarkin, C., et al. (2002). NIST/SEMATECH e-Handbook of Statistical Methods, Ch. 4 “Process Modeling”. itl.nist.gov/div898/handbook.

Frequently asked questions

Is my data sent to a server?
No. Reading the data, fitting, plotting and writing the script all happen in your browser. Nothing is uploaded.
Do the results match SciPy?
Yes. The fit minimises the same sum of squares as scipy.optimize.curve_fit with the Levenberg–Marquardt method, and the covariance, standard errors and confidence intervals are computed as curve_fit computes them, including the absolute_sigma setting. The script the page writes starts from the page’s result and prints the same values. With bounds, SciPy switches to its trust-region method, which ends in the same place when the fit settles inside the bounds.
How does the page decide which names are fitted?
Every name in the equation that is not a variable, a function, pi or e is a parameter. The variable is the one listed in f(x) =, or a usual name such as x, t, T or V, or a name that matches a column header. You can move any name between variable and parameter, and fit e as a parameter if you meant one.
What if the fit finds a poor curve or does not converge?
The page searches for starting values itself, but a model with several minima, such as a sum of peaks or an oscillation, can still settle in the wrong one. Give starting values near the answer, set bounds, or hold a parameter fixed at a known value; Start from the fit copies the current result into the starting values so you can refine it step by step.
Why does it say two parameters cannot be told apart?
The data fix only a combination of them. In k = A*exp(-Ea/(R*T)) only the ratio Ea/R matters, so R has to be held at its known value. The page recognises common physical constants (R, k_B, N_A, F, h, hbar, Vt) and offers to hold them fixed.
What do the standard errors and confidence intervals mean?
The standard error is the square root of the parameter’s variance from the covariance matrix, scaled by the reduced χ² unless your uncertainties are absolute. The 95% interval is the value plus or minus Student’s t on n − p degrees of freedom times the standard error. A parameter that ends on a bound is flagged, because its uncertainty then describes a constrained estimate.
What are the uncertainty column and “absolute”?
Give a column of one-standard-deviation uncertainties of y and each point is weighted by 1/σ². Tick absolute when they are real standard deviations: the parameter errors then follow from them directly, and the reduced χ² tells you whether the scatter matches them (about 1). Untick it when they are only relative weights: the errors are then scaled to the scatter of the data.
Can I fit a function of two variables?
Yes. Write z = a*x + b*y + c, or list the variables as f(x, y) =, and give each its column. The plot then shows the observed values against the fitted ones, with the line where they would be equal.

Runs entirely in your browser, no data leaves your device.