.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/1d-interp.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_auto_examples_1d-interp.py: =========================== 1-Dimensional Interpolation =========================== .. GENERATED FROM PYTHON SOURCE LINES 6-61 .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_001.png :alt: k=0 :srcset: /auto_examples/images/sphx_glr_1d-interp_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_002.png :alt: k=0 :srcset: /auto_examples/images/sphx_glr_1d-interp_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_003.png :alt: k=0 :srcset: /auto_examples/images/sphx_glr_1d-interp_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_004.png :alt: k=1 :srcset: /auto_examples/images/sphx_glr_1d-interp_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_005.png :alt: k=1 :srcset: /auto_examples/images/sphx_glr_1d-interp_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_006.png :alt: k=1 :srcset: /auto_examples/images/sphx_glr_1d-interp_006.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_007.png :alt: k=2 :srcset: /auto_examples/images/sphx_glr_1d-interp_007.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_008.png :alt: k=2 :srcset: /auto_examples/images/sphx_glr_1d-interp_008.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_009.png :alt: k=2 :srcset: /auto_examples/images/sphx_glr_1d-interp_009.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_010.png :alt: k=3 :srcset: /auto_examples/images/sphx_glr_1d-interp_010.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_011.png :alt: k=3 :srcset: /auto_examples/images/sphx_glr_1d-interp_011.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_1d-interp_012.png :alt: k=3 :srcset: /auto_examples/images/sphx_glr_1d-interp_012.png :class: sphx-glr-multi-img .. code-block:: Python :lineno-start: 7 import ndsplines import numpy as np import matplotlib.pyplot as plt from scipy import interpolate from scipy.stats import norm def gaussian(x_in): z = norm.ppf(0.9995) x = z * (2 * x_in - 1) return norm.pdf(x) def sin(x_in): x = np.pi * (x_in - 0.5) return np.sin(x) def tanh(x_in): x = 2 * np.pi * (x_in - 0.5) return np.tanh(x) funcs = [gaussian, sin, tanh] x = np.linspace(0, 1, 9) xx = np.linspace(-0.25, 1.25, 1024) k = 3 for degree in range(0, 4): for func in funcs: fvals = func(x) truef = func(xx) plt.figure() plot_sel = slice(None) plt.gca().set_prop_cycle(None) test_Bspline = interpolate.make_interp_spline(x, fvals, k=degree) splinef = test_Bspline(xx.copy(), extrapolate=True) plt.plot( xx, splinef, "--", lw=3.0, label="scipy.interpolate.make_interp_spline" ) test_NDBspline = ndsplines.make_interp_spline(x, fvals, degrees=degree) NDsplinef = test_NDBspline(xx.copy()) plt.plot(xx, NDsplinef, label="ndspline.make_interp_spline") plt.plot(xx, truef, "k--", label="True " + func.__name__) plt.plot(x, fvals, "ko") plt.title("k=%d" % degree) plt.legend(loc="best") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.883 seconds) .. _sphx_glr_download_auto_examples_1d-interp.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 1d-interp.ipynb <1d-interp.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 1d-interp.py <1d-interp.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 1d-interp.zip <1d-interp.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_