.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` 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 ============================ .. image:: /intro/scipy/auto_examples/images/sphx_glr_plot_interpolation_001.png :class: sphx-glr-single-img .. code-block:: python # 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 from scipy.interpolate import interp1d linear_interp = interp1d(measured_time, measures) interpolation_time = np.linspace(0, 1, 50) linear_results = linear_interp(interpolation_time) cubic_interp = interp1d(measured_time, measures, kind='cubic') cubic_results = cubic_interp(interpolation_time) # Plot the data and the interpolation from matplotlib import 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() **Total running time of the script:** ( 0 minutes 0.018 seconds) .. _sphx_glr_download_intro_scipy_auto_examples_plot_interpolation.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_interpolation.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_interpolation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_