Skip to main content

Student-friendly least-squares curve fitting for Python

Project description

LabFit - least-squares curve fitting for Python

Documentation · GitHub · Gallery

LabFit is a small, student-friendly Python library for least-squares curve fitting, error propagation, and publication-quality plotting - built on NumPy, SciPy, and Matplotlib.

pip install labfit

Quick start

from labfit import fit, plot_fit

result = fit("data.csv", model="exponential")
plot_fit(result)
print(f"χ²/ν = {result.reduced_chi2:.3f}")

Three lines: CSV → fit → plot → goodness-of-fit.

Features

  • Built-in models - linear, quadratic, Gaussian, Lorentzian, exponential, power law, logistic, sinc, bimodal Gaussian, damped oscillator, and more - all by name.
  • Reduced χ² on every fit result, so you can immediately assess goodness-of-fit.
  • Asymmetric & correlated errors - handle sigma_low/sigma_high and full covariance matrices without rewriting propagation code.
  • Multi-series fitting - fit and compare many data sets on shared or independent axes.
  • Plots - residual panels, multi-fit grids, proper axis labels.
  • 100 % Python - no compiled extensions, installs everywhere.

Longer example

import numpy as np
from labfit import fit, plot_fit

rng = np.random.default_rng(42)
x = np.linspace(-5, 5, 200)
y = 3.0 * np.exp(-0.5 * ((x - 0.5) / 1.2) ** 2) + rng.normal(0, 0.05, size=x.size)

result = fit(x, y, model="gaussian")
print(f"amplitude = {result.params['amplitude']:.3f}")
print(f"mean      = {result.params['mean']:.3f}")
print(f"sigma     = {result.params['sigma']:.3f}")
print(f"χ²/ν      = {result.reduced_chi2:.4f}")

plot = plot_fit(result, show_residuals=True)
plot.save("gaussian_fit.png")

Dependencies

  • Python ≥ 3.10
  • NumPy, SciPy, Matplotlib

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labfit-0.2.0.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

labfit-0.2.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file labfit-0.2.0.tar.gz.

File metadata

  • Download URL: labfit-0.2.0.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for labfit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 398bbcdef3f68c260e4659b64dfd606ad7e9648346a1f8a6798878616897bc52
MD5 62fb1bc45910ccec27c6693410bf9016
BLAKE2b-256 d5e00e2329ebd843009109b326c3250c06e37ea2e717137ffd97360eb88250e3

See more details on using hashes here.

File details

Details for the file labfit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: labfit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for labfit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 197caa5158c8e756fbdcc2ea4dec4712f04ff6c2b3d58b6528078ed4cef2580e
MD5 98387a6dec795e8454e10c1c8d41f63b
BLAKE2b-256 c36021fbad1dd9e4fa3b31f5ef3cfd2044f15a65447a727a9b0f9d3705f9dedc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page