A toolbox providing interactive fitting tools for matplotlib
pip install anafit==0.1.2
Anafit is a package providing fitting tools for matplotlib figures. It is largely inspired from the Ezyfit toolbox for Matlab.
Once you have installed the above-mentioned dependencies, you can use pip to download and install the latest release with a single command:
python3 -m pip install anafit
To un-install, use:
python3 -m pip uninstall anafit
Note that you can also just download and add the anafit repository to your PYTHONPATH.
First, import anafit:
import anafit
Note that importing anafit will switch matplotlibâs backend to âQt5Aggâ, destroying your current figures ! To prevent this, the best is to import anafit BEFORE importing matplotlib.pyplot or pylab.
This is done simply by calling anafit.Figure() class:
fig = plt.figure()
ana = anafit.Figure(fig)
If no argument is passed to anafit.Figure(), the anafit button will be added to the current active figure.
In case several curves are plotted, you can select the one you wanna fit in the âDatasetâ menu. The dataset are represented by a icon filled with the color of the curve, followed by their marker.
Then, in the âShow Fitâ menu, you can select predefined fitting functions, sorted by types (linear, power, etcâŠ), or your own saved fitting functions, or any function you want to define on the way, using âOther FitâŠâ.
The fitting curve will appear as an orange line on your figure, and its parameters will appear in the Python console. You can access them anytime through the attribute ana.lastFit . More generally, an history of fits is stored in ana.fits . These anafit.Fit object contains not only the fit informations, but also the handles of the fit line, allowing to easily change the style of the fit curve. For instance, you can change the color of the last fit by simply running:
ana.fits[-1].linfit.set_color(ârâ)
You can restrict the range on which you wanna fit your datas in the âDefine Rangeâ menu. This menu displays the current range, and offers the possibility to set the range manually in a dialog (âDefineâŠâ) or by selecting two points on the figure (âDefine ROIâ). You can restore the full range by selecting âResetâ.
You can create your own fitting functions in the âEdit User Fitâ menu. They will then appear in the âShow Fitâ menu. Those fitting functions are stored in a text file in the anafit repository, that you can edit by hand. Clicking âResetâ deletes all custom fitting functions, but let one as an example.
You can draw a line on the figure by selecting âDraw Lineâ, and remove it using âUndo Lineâ. Use âGet Slopeâ to access the parameters of this line: in log-log scale, this returns the prefactor and the exponent of a power law.
You can draw a line corresponding to a given slope (a given exponent in log-log scale) using âShow Slopeâ.
You can display the range of confidence of the fit curve by selecting âShow Confidenceâ. The interval of confidence is evaluated using the square root of the diagonal of the covariance matrix.