:orphan:



.. _sphx_glr_examples:

Examples gallery
================

Below are examples of the different things you can do with lmfit.
Click on any image to see the complete source code and output.

We encourage users (i.e., YOU) to submit user-guide-style, documented,
and preferably self-contained examples of how you use lmfit for
inclusion in this gallery! Please note that many of the examples
below currently do *not* follow these guidelines yet.



.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Simple example demonstrating how to read in the data using pandas and supply the elements of th...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_use_pandas_thumb.png
     :alt: Fit with Data in a pandas DataFrame

     :ref:`sphx_glr_examples_example_use_pandas.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_use_pandas

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="ExpressionModels allow a model to be built from a user-supplied expression. See: https://lmfit....">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_expression_model_thumb.png
     :alt: Using an ExpressionModel

     :ref:`sphx_glr_examples_example_expression_model.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_expression_model

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Sometimes specifying boundaries using min and max are not sufficient, and more complicated (ine...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_fit_with_inequality_thumb.png
     :alt: Fit Using Inequality Constraint

     :ref:`sphx_glr_examples_example_fit_with_inequality.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_fit_with_inequality

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example compares the &quot;leastsq&quot; and &quot;differential_evolution&quot; algorithms on a fairly simple ...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_diffev_thumb.png
     :alt: Fit Using differential_evolution Algorithm

     :ref:`sphx_glr_examples_example_diffev.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_diffev

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="A major advantage of using lmfit is that one can specify boundaries on fitting parameters, even...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_fit_with_bounds_thumb.png
     :alt: Fit Using Bounds

     :ref:`sphx_glr_examples_example_fit_with_bounds.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_fit_with_bounds

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="The reduce_fcn specifies how to convert a residual array to a scalar value for the scalar minim...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_reduce_fcn_thumb.png
     :alt: Fit Specifying Different Reduce Function

     :ref:`sphx_glr_examples_example_reduce_fcn.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_reduce_fcn

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="SymPy is a Python library for symbolic mathematics. It can be very useful to build a model with...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_sympy_thumb.png
     :alt: Building a lmfit model with SymPy

     :ref:`sphx_glr_examples_example_sympy.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_sympy

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Fit with Algebraic Constraint">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_fit_with_algebraic_constraint_thumb.png
     :alt: Fit with Algebraic Constraint

     :ref:`sphx_glr_examples_example_fit_with_algebraic_constraint.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_fit_with_algebraic_constraint

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Fitting multiple (simulated) Gaussian data sets simultaneously.">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_fit_multi_datasets_thumb.png
     :alt: Fit Multiple Data Sets

     :ref:`sphx_glr_examples_example_fit_multi_datasets.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_fit_multi_datasets

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Specifying an analytical function to calculate the Jacobian can speed-up the fitting procedure.">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_fit_with_derivfunc_thumb.png
     :alt: Fit Specifying a Function to Compute the Jacobian

     :ref:`sphx_glr_examples_example_fit_with_derivfunc.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_fit_with_derivfunc

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This notebook shows a simple example of using the lmfit.Model class. For more information pleas...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_Model_interface_thumb.png
     :alt: Fit using the Model interface

     :ref:`sphx_glr_examples_example_Model_interface.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_Model_interface

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Outliers can sometimes be identified by assessing the influence of each datapoint. To assess th...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_detect_outliers_thumb.png
     :alt: Outlier detection via leave-one-out

     :ref:`sphx_glr_examples_example_detect_outliers.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_detect_outliers

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Calculate Confidence Intervals">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_confidence_interval_thumb.png
     :alt: Calculate Confidence Intervals

     :ref:`sphx_glr_examples_example_confidence_interval.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_confidence_interval

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This notebook shows how to fit the parameters of a complex resonator, using lmfit.Model and def...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_complex_resonator_model_thumb.png
     :alt: Complex Resonator Model

     :ref:`sphx_glr_examples_example_complex_resonator_model.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_complex_resonator_model

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="FIXME: this is a useful examples; however, it doesn&#x27;t run correctly anymore as the PTSampler wa...">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_lmfit_emcee_model_selection_thumb.png
     :alt: Model Selection using lmfit and emcee

     :ref:`sphx_glr_examples_lmfit_emcee_model_selection.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/lmfit_emcee_model_selection

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="This example illustrates how to handle two-dimensional data with lmfit.">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_two_dimensional_peak_thumb.png
     :alt: Fit Two Dimensional Peaks

     :ref:`sphx_glr_examples_example_two_dimensional_peak.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_two_dimensional_peak

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Global minimization using the brute method (a.k.a. grid search)">

.. only:: html

 .. figure:: /examples/images/thumb/sphx_glr_example_brute_thumb.png
     :alt: Global minimization using the ``brute`` method (a.k.a. grid search)

     :ref:`sphx_glr_examples_example_brute.py`

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /examples/example_brute
.. raw:: html

    <div class="sphx-glr-clear"></div>



.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-gallery


  .. container:: sphx-glr-download sphx-glr-download-python

    :download:`Download all examples in Python source code: examples_python.zip </examples/examples_python.zip>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

    :download:`Download all examples in Jupyter notebooks: examples_jupyter.zip </examples/examples_jupyter.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
