{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nFit with Data in a pandas DataFrame\n===================================\n\nSimple example demonstrating how to read in the data using pandas and supply\nthe elements of the DataFrame from lmfit.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport pandas as pd\n\nfrom lmfit.models import LorentzianModel" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "read the data into a pandas DataFrame, and use the 'x' and 'y' columns:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dframe = pd.read_csv('peak.csv')\n\nmodel = LorentzianModel()\nparams = model.guess(dframe['y'], x=dframe['x'])\n\nresult = model.fit(dframe['y'], params, x=dframe['x'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and gives the plot and fitting results below:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "result.plot_fit()\nplt.show()\n\nprint(result.fit_report())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }