Lab data analysis with MesPy

MesPy is a collection of Python functions for the physics lab. It shows the distribution of your measurements with their mean and standard deviation, fits a line to your data weighting each point by its uncertainty, and returns the slope and intercept with their uncertainties, along with the residuals.

Edit the example data and press Run: the real lin_fit computes the plot and the TOML in your browser.

Python

Edit the measurements and press Run.

The first run downloads Python and the scientific packages. Analysis runs in your browser.

The main functions

histogram
Histogram Illustrative example: frequency bars, a mean line and a band of one standard deviation on each side. 051015−202 x x̄−σ+σ
A distribution, its mean and the ±σ band. Illustrative example.

Histogram

Group your measurements in a histogram. See the mean and standard deviation to understand where your data clusters and how much it spreads.

histogram(measurements)
Explore histogram
lin_fit
Linear fit Illustrative example: experimental points with uncertainty bars along an increasing straight line. 012345123 xy
Measurements with uncertainties and a fitted line. Illustrative example.

Linear fit

Find the line that describes your measurements. Get the slope, intercept and their uncertainties, with a residual plot to explore the result.

lin_fit(x, y, sigma_y)
Explore lin_fit

Both draw with Matplotlib and return objects you can reuse: the figure and axes for the histogram, a result with parameters, uncertainties and residuals for the fit.

In depth in the API Reference

Each function has a page with its signature, parameters and input checks. For lin_fit you will find the OLS and WLS cases, the propagation of x uncertainties and the χ² diagnostics; for histogram, how the bins are built and the normalizations.

Open the API Reference

Install MesPy

MesPy requires Python 3.12 or later. The guide covers installation on Google Colab and on your computer, then the first import.

Installation guide