.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/numpy/auto_examples/plot_polyfit.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_intro_numpy_auto_examples_plot_polyfit.py: Fitting to polynomial ===================== Plot noisy data and their polynomial fit .. GENERATED FROM PYTHON SOURCE LINES 8-21 .. image-sg:: /intro/numpy/auto_examples/images/sphx_glr_plot_polyfit_001.png :alt: plot polyfit :srcset: /intro/numpy/auto_examples/images/sphx_glr_plot_polyfit_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import matplotlib.pyplot as plt rng = np.random.default_rng(27446968) x = np.linspace(0, 1, 20) y = np.cos(x) + 0.3 * rng.random(20) p = np.poly1d(np.polyfit(x, y, 3)) t = np.linspace(0, 1, 200) plt.plot(x, y, "o", t, p(t), "-") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.037 seconds) .. _sphx_glr_download_intro_numpy_auto_examples_plot_polyfit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_polyfit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_polyfit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_polyfit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_