Like Matplotlib, SciPy is part of the Numpy software system. SciPy adds more features to Numpy. The one we are interested in here is the optimization package, and particularly curve fitting through minimizing the chi square difference between a dataset and a model. The package we want is scipy.optimize and the specific procedure is curve_fit. A particularly powerful feature of this package is that it takes, as input, a Python model function in symbolic form. Here, we illustrate its use with a simple example.

For documentation and more details, see scipy.optimize.