Anafit is a visual curve fitting tool for Matplotlib. It is largely inspired from the Ezyfit toolbox for Matlab. It allows you to fit a curve to your data by interactively adjusting the parameters of the model. It is designed to be easy to use and to provide immediate feedback on the quality of the fit. Anafit is built on top of matplotlib
and uses the scipy
library for curve fitting. It is open source and available on GitHub.
Anafit provides the following features:
First, install the required dependencies:
pip install numpy scipy matplotlib PyQt5
Then, install Anafit:
pip install anafit
Anafit is very simple to use. Simply pass the matplotlib Figure
instance to the anafit Figure
class, and you are ready to go:
import matplotlib.pyplot as plt
import numpy as np
import anafit
fig, ax = plt.subplots()
ax.plot(
np.arange(0, 100, 1),
np.arange(50, 250, 2) + 10 * (np.random.rand(100) - 1 / 2),
"+",
)
ana = anafit.Figure(fig)
plt.show()
This creates a button in the toolbar of the plot, from which you can access the Anafit interface.
Anafit also enables you to draw lines on the plot and get their corresponding slopes, or draw lines of a given slope. This is very convenient in log-log plots, to show the power-law behavior of the data.
Anafit can do many more things, such as defining custom fit functions. You can use the anafit.Figure
instance you created to add the anafit menu to your plot to access all properties of your fits, including their parameters but also the line
objects to modify the style of the curves (check the ana.fits
list).
Some example scripts are provided in the examples
directory of the repository.
Anafit has some limitations worth keeping in mind:
Qt5Agg
backend of matplotlib.