{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\ndoc_model_loadmodel.py\n======================\n\n

Note

This example *does* actually work, but running from within sphinx-gallery fails to find symbols saved in the save file.

\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "##\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n##\n# \nimport matplotlib.pyplot as plt\nimport numpy as np\n\nfrom lmfit.model import load_model\n\n\ndef mysine(x, amp, freq, shift):\n return amp * np.sin(x*freq + shift)\n\n\ndata = np.loadtxt('sinedata.dat')\nx = data[:, 0]\ny = data[:, 1]\n\nmodel = load_model('sinemodel.sav', funcdefs={'mysine': mysine})\nparams = model.make_params(amp=3, freq=0.52, shift=0)\nparams['shift'].max = 1\nparams['shift'].min = -1\nparams['amp'].min = 0.0\n\nresult = model.fit(y, params, x=x)\nprint(result.fit_report())\n\nplt.plot(x, y, 'bo')\nplt.plot(x, result.best_fit, 'r-')\nplt.show()\n# " ] } ], "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 }