A toolbox providing interactive fitting tools for matplotlib
Project description
Anafit is a package providing fitting tools for matplotlib figures. It is largely inspired from the Ezyfit toolbox for Matlab.
- Source code repository and issue tracker:
- Python Package Index:
Requirements
- Python:
Anafit has been coded using Python 3.5 from Anaconda distribution.
- pip/setuptools:
Those are the most convenient way to install Anafit and its dependencies. Most likely they are already installed in your system, but if not, please refer to pip doc webpage.
- Matplotlib and PyQt5:
When called, Anafit menu, based on PyQt5, will appear as a new button in the matplotlib figure toolbar. However, this requires Qt5Agg as matplotlib’s backend. WARNING : When imported, anafit will switch your actual backend to Qt5Agg, destroying all figures already constructed during your session.
- Other packages:
To fit, Anafit uses scipy.optimize.curve_fit function from scipy module. It also uses numpy , os , sys , functools and finally json (for custom fit function saving in a text file).
Installation
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.
Usage
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.
Fitting a curve
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’)
Defining a region of interest (ROI)
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’.
Creating custom fit functions
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.
Getting slopes from drawn lines
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’.
Displaying fit infos
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file anafit-0.1.6.tar.gz
.
File metadata
- Download URL: anafit-0.1.6.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac6ebfeaa3db0f5f240635b6de745b6959af141689fefc13735478de0f79b7e |
|
MD5 | 3c22a5357e31577e5e66e10502a56208 |
|
BLAKE2b-256 | 751a4b94d0552cdd0d1ca0e25ec850692962f61c2c4957c4f95d13901896a39b |
File details
Details for the file anafit-0.1.6-py3-none-any.whl
.
File metadata
- Download URL: anafit-0.1.6-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11bf08728b480a383f564fc6eaa44099845ce5a8b46e4db68dcce52fdbe78b5f |
|
MD5 | a6e745ea1ffa201160f8d8b0093a941e |
|
BLAKE2b-256 | e7babedacf9330d2535d6cdcb052fb1714c022ab802c887e83c2a565745c041e |