Curve fitting

How to fit a curve to data

To fit a curve to data, decide exactly which observations the estimator sees, choose a model family from the mechanism, estimate its parameters, then check the residuals and the sensitive choices before you report anything. The fitted line is one output of that sequence, not the conclusion. This guide walks through the six steps and shows which method suits which shape of data.

Updated · 5 min read

On this page
  1. The curve-fitting workflow in six steps
  2. Match the method to the shape of your data
  3. Linear vs nonlinear regression
  4. Check residuals and sensitivity before you trust the fit
  5. Report the fit so someone else can repeat it
  6. Fitting curves in Autoplot, and where it stops
  7. Frequently asked questions

The curve-fitting workflow in six steps

  1. Define the observations. Record the response, predictors, units, measurement uncertainty, exclusions, transforms and fit range. Plot the raw data first and look for impossible values, duplicates, separate groups, drift and changing spread.
  2. Choose the model family. Write the equation, the meaning and units of each parameter, and the domain where it should hold. Decide how errors enter: constant, proportional, or known per point.
  3. Estimate the parameters. Use the estimator that matches the data shape and error model, with deliberate starting values if the model is nonlinear.
  4. Inspect the residuals. Plot them against fitted values, each predictor and acquisition order before you interpret any parameter.
  5. Test sensitivity. Refit with nearby ranges, cutoffs, exclusions, bin choices and starting values. Note which conclusions move.
  6. Report the fit. Keep enough detail for someone else to repeat it exactly.

Keep exclusions explicit throughout. Removing an inconvenient point after seeing the result changes the analysis, and the record should say so.

Match the method to the shape of your data

The same bell-shaped picture can come from paired measurements, a histogram or a fitted surface. Decide what the estimator will actually see before you choose software or a solver.

Data shapeTypical methodIn Autoplot
Paired X/Y observationsLeast squares: linear, polynomial or nonlinear in the parametersLinear and polynomial trend overlays; a custom nonlinear model via the assistant or your own SciPy code
Binned density (histogram)Least squares on bin centres and densities, or a likelihood fit on the raw valuesHistogram fit: 1–3 Gaussian components or a predefined or custom formula
Distribution tailA fit above a cutoff on the raw values, read on the CCDFCCDF tail fit and xmin diagnostic (see power-law fitting)
Surface z = f(x, y) or 2D densityTwo-dimensional least squaresGaussian or custom surface and density-map fits on heat maps

A fit to bin centres depends on the bin count and range; a fit to raw observations does not. If you only have binned data, keep the original edges and normalisation with the file.

Autoplot histogram of cell diameters with a dashed single-Gaussian fit and a solid two-component mixture fit drawn over the same density bars
Two candidate models against one representation of the data. The single Gaussian misses both peaks; the mixture follows them, which is a reason to check its residuals, not proof that it is right.

Linear vs nonlinear regression

Linear regression means the model is linear in its parameters: y = a + bx + cx² is linear, although the curve bends. Its least-squares solution is unique and needs no starting values. Nonlinear regression covers models such as y = A·e^(−x/τ) + c, where the solver searches iteratively and can stop at a local minimum.

Transforming a nonlinear model into a straight line, for example by taking logarithms, is legitimate only if the errors behave on the transformed scale. Logs turn additive noise into something else and weight small values heavily. Fit on the scale where the noise is roughly constant, or weight the points.

For a nonlinear fit, take starting values from a preliminary plot, physical expectations or a simpler model, apply bounds only where they have physical meaning, and rerun from several starts. The nonlinear curve fitting guide covers starting values, bounds, scaling and convergence in detail.

Check residuals and sensitivity before you trust the fit

A residual is the observed value minus the model's prediction. Plot residuals against fitted values, each predictor and observation order, with a zero line. Curvature means the functional form is wrong, a funnel means the variance changes, and runs in acquisition order point to drift. The guide to interpreting residual plots maps each pattern to its likely cause and the next check.

Then test the choices that could change the conclusion: the fit range, a cutoff, a baseline, the bin count, the weighting. If a parameter moves by more than its reported error when a defensible choice changes, report that sensitivity rather than one number. R² describes how closely the curve follows the points used; it neither tests the model nor compares it with alternatives.

Autoplot xmin diagnostic plotting Kolmogorov–Smirnov distance against candidate cutoff values with the selected cutoff marked
A data-dependent choice, here a tail cutoff, compared with its neighbours. A sensitivity check shows whether the result belongs to the data or to the choice.

Report the fit so someone else can repeat it

Keep and report:

  • the exact input data, with every filter, transform, binning and exclusion;
  • the model equation, parameterisation, units, starting values, bounds, weighting and fit range;
  • the software and version, the estimator, the convergence status and the uncertainty method;
  • the residual plots and the sensitivity checks that could change the conclusion;
  • the editable project or script and the exact figure used.

Parameter errors from a covariance matrix assume the model and error structure are right. For consequential work, add a bootstrap or simulation check rather than relying on one asymptotic estimate.

In Autoplot

Fitting curves in Autoplot, and where it stops

Autoplot keeps the data, the fit controls, the plot and the export in one project on your Mac.

  • X&Y plots: linear and polynomial trend overlays over a chosen interval, in the free plan.
  • Histogram fit: nonlinear least squares on bin centres and densities, with 1–3 Gaussian components or a predefined or custom formula with your own starting guesses. It reports the fitted parameters with errors and R², and Export Fit Function turns the curve into a reusable derived function. Free.
  • Distributions: the log-binned power-law PDF fit (free), the CCDF tail fit and the xmin diagnostic (Plus).
  • Surfaces: Gaussian or custom surface and density-map fits on heat maps, whose fitted surface can then be shown in a 3D plot (Plus).

There is no general nonlinear X/Y fitter card with user-set bounds and weights. For a custom model on paired data, ask the assistant: it writes the Python (typically SciPy), shows it to you before it runs, runs it on your Mac and keeps the script. You can also fit in your own environment and bring the results back as variables. See the method notes on the features page, or compare tools in curve-fitting software for Mac.

Frequently asked questions

Frequently asked questions
What is the difference between linear and nonlinear regression?Linear regression is linear in the parameters, so polynomials count as linear and have a unique least-squares solution. Nonlinear regression has parameters inside functions such as exponentials, needs starting values and can converge to a local minimum.
Is a high R² enough to accept a curve fit?No. R² summarises how closely the curve follows the fitted points. A wrong model can score highly while leaving systematic structure in the residuals, so inspect the residuals and test sensitivity.
Should I log-transform data before fitting?Only if the noise is roughly constant on the log scale. Otherwise fit the original model directly with nonlinear least squares, or weight the points to match the measurement error.

Sources

Autoplot behaviour comes from the app's documentation for X&Y data operations, the histogram fit and histogram custom fit, and the heat-map fits, checked on 9 October 2026, and from the features page. Model-adequacy and residual guidance follow the NIST/SEMATECH e-Handbook sections on checking model adequacy, residual analysis and a misleading fitted overlay. Nonlinear least-squares controls and covariance cautions come from the SciPy curve_fit reference.

Try it on your own data.

Linear and polynomial trends and histogram fits are in Autoplot's free plan. Heat-map surface and density fits are part of Plus, which is free for the first 30 days.

Set up a nonlinear fit →
Download free for Mac Mac App Store

Apple silicon · macOS 15 or later · Free plan · Plus free for 30 days

Send to my Mac

Autoplot runs on a Mac. Send the link to yourself, or open it in the Mac App Store.