Skip to main content

Data fitting system with SciPy.

Project description

PyPI Version MIT License Coverage Status Build Status

Check out the example fits on Fitalyzer. See the Fitalyzer README for details on how to use Fitalyzer for visualizing your fits.


Documentation generated from source with pdoc for the latest version is hosted at

To get started quickly, check out the examples.

Then, refer to the source documentation for details on how to use each class.

Basic usage

from scipy_data_fitting import Data, Model, Fit, Plot

# Load data from a CSV file.
data = Data('linear')
data.path = 'linear.csv'
data.error = (0.5, None)

# Create a linear model.
model = Model('linear')
model.add_symbols('t', 'v', 'x_0')
t, v, x_0 = model.get_symbols('t', 'v', 'x_0')
model.expressions['line'] = v * t + x_0

# Create the fit using the data and model.
fit = Fit('linear', data=data, model=model)
fit.expression = 'line'
fit.independent = {'symbol': 't', 'name': 'Time', 'units': 's'}
fit.dependent = {'name': 'Distance', 'units': 'm'}
fit.parameters = [
    {'symbol': 'v', 'guess': 1, 'units': 'm/s'},
    {'symbol': 'x_0', 'value': 1, 'units': 'm'},

# Save the fit result to a json file.
fit.to_json( + '.json', meta=fit.metadata)

# Save a plot of the fit to an image file.
plot = Plot(fit) + '.svg')

Controlling the fitting process

The above example will fit the line using the default algorithm `scipy.optimize.curve_fit <>`__.

For a linear fit, it may be more desirable to use a more efficient algorithm.

For example, to use `numpy.polyfit <>`__, one could set a fit_function and allow both parameters to vary,

fit.parameters = [
    {'symbol': 'v', 'guess': 1, 'units': 'm/s'},
    {'symbol': 'x_0', 'guess': 1, 'units': 'm'},
fit.options['fit_function'] = lambda f, x, y, p0, **op: (numpy.polyfit(x, y, 1), )

Controlling the fitting process this way allows, for example, incorporating error values and computing and returning goodness of fit information.

See `scipy_data_fitting.Fit.options <>`__ for further details on how to control the fit and also how to use lmfit.


This package is registered on the Python Package Index (PyPI) at

Add this line to your application’s requirements.txt:


And then execute:

$ pip install -r requirements.txt

Or install it yourself as:

$ pip install scipy-data_fitting

Depending on your system configuration, you may need to run the above commands with sudo. Alternatively, you may want to use a virtualenv, which is beyond the scope of this documentation.

Note that the large scientific packages such as NumPy, SciPy, and matplotlib may also be available via your system’s package manager.

To live on the bleeding edge, instead of the package name scipy-data_fitting, you can use this repository directly with


Note about dependency versions

This package intentionally does not specify dependency versions. Thus, pip will use whatever required packages are currently installed or fetch the latest available version for missing dependencies.

If you want to control what package versions are used, you should specify them explicitly in your project’s own requirements.txt.


Source Repository

The source is hosted at GitHub. Fork it on GitHub, or clone the project with

$ git clone

Install dependencies with

$ pip install -r requirements.txt

and install the package in development mode with

$ python develop

Depending on your system configuration, you may need to run the above command with sudo or use a virtualenv.

Note that the large scientific packages such as NumPy, SciPy, and matplotlib may also be available via your system’s package manager.


Generate documentation with pdoc by running

$ make docs


Run the tests with

$ make tests


Run an example with

$ python examples/

or run all the examples with

$ make examples


This code is licensed under the MIT license.


This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.

Project details

Release history Release notifications

History Node


History Node


History Node


History Node


History Node


History Node


This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
scipy_data_fitting-0.2.4-py3.4.egg (44.8 kB) Copy SHA256 hash SHA256 Egg 3.4 Apr 6, 2014
scipy-data_fitting-0.2.4.tar.gz (22.5 kB) Copy SHA256 hash SHA256 Source None Apr 6, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page