.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "intro/scipy/auto_examples/plot_interpolation.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_scipy_auto_examples_plot_interpolation.py: ============================ A demo of 1D interpolation ============================ .. GENERATED FROM PYTHON SOURCE LINES 7-31 .. image-sg:: /intro/scipy/auto_examples/images/sphx_glr_plot_interpolation_001.png :alt: plot interpolation :srcset: /intro/scipy/auto_examples/images/sphx_glr_plot_interpolation_001.png :class: sphx-glr-single-img .. code-block:: default # Generate data import numpy as np np.random.seed(0) measured_time = np.linspace(0, 1, 10) noise = 1e-1 * (np.random.random(10)*2 - 1) measures = np.sin(2 * np.pi * measured_time) + noise # Interpolate it to new time points import scipy as sp linear_interp = sp.interpolate.interp1d(measured_time, measures) interpolation_time = np.linspace(0, 1, 50) linear_results = linear_interp(interpolation_time) cubic_interp = sp.interpolate.interp1d(measured_time, measures, kind='cubic') cubic_results = cubic_interp(interpolation_time) # Plot the data and the interpolation import matplotlib.pyplot as plt plt.figure(figsize=(6, 4)) plt.plot(measured_time, measures, 'o', ms=6, label='measures') plt.plot(interpolation_time, linear_results, label='linear interp') plt.plot(interpolation_time, cubic_results, label='cubic interp') plt.legend() plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.057 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_interpolation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_interpolation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_interpolation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_