Skip to main content

Student-friendly least-squares curve fitting for Python

Project description

LabFit - least-squares curve fitting for Python

Documentation · Quick start · 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 quick_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 = quick_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.1.0.tar.gz (33.0 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.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for labfit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 06d6053168412514ff2192d8f3979d4170bca2d40a65e465c0689da8d0f3101f
MD5 4a9f32cc194f5ea9423564867f667518
BLAKE2b-256 26605169801ce136d2e07be5e4ff4aa230403f5b4a0f31b03bf10699f266c664

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for labfit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 672e3b5eb79d676497c1ae0072387b32dc56ddb3e2d46fa96b9bf600ef45fa46
MD5 8132dbd2acc945df725af09679f8bcb7
BLAKE2b-256 c7a1bc81d0c92f29e903ace0b50e6f8f979b227433b73b8ca6dba65fcbd90b36

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