.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/06_exact_values_example_1D.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_examples_06_exact_values_example_1D.py: Exact Values ============ PyKrige demonstration and usage as a non-exact interpolator in 1D. .. GENERATED FROM PYTHON SOURCE LINES 9-61 .. image-sg:: /examples/images/sphx_glr_06_exact_values_example_1D_001.png :alt: 06 exact values example 1D :srcset: /examples/images/sphx_glr_06_exact_values_example_1D_001.png :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from pykrige.ok import OrdinaryKriging plt.style.use("ggplot") np.random.seed(42) x = np.linspace(0, 12.5, 50) xpred = np.linspace(0, 12.5, 393) y = np.sin(x) * np.exp(-0.25 * x) + np.random.normal(-0.25, 0.25, 50) # compare OrdinaryKriging as an exact and non exact interpolator uk = OrdinaryKriging( x, np.zeros(x.shape), y, variogram_model="linear", exact_values=False ) uk_exact = OrdinaryKriging(x, np.zeros(x.shape), y, variogram_model="linear") y_pred, y_std = uk.execute("grid", xpred, np.array([0.0]), backend="loop") y_pred_exact, y_std_exact = uk_exact.execute( "grid", xpred, np.array([0.0]), backend="loop" ) y_pred = np.squeeze(y_pred) y_std = np.squeeze(y_std) y_pred_exact = np.squeeze(y_pred_exact) y_std_exact = np.squeeze(y_std_exact) fig, ax = plt.subplots(1, 1, figsize=(10, 4)) ax.scatter(x, y, label="Input Data") ax.plot(xpred, y_pred_exact, label="Exact Prediction") ax.plot(xpred, y_pred, label="Non Exact Prediction") ax.fill_between( xpred, y_pred - 3 * y_std, y_pred + 3 * y_std, alpha=0.3, label="Confidence interval", ) ax.legend(loc=9) ax.set_ylim(-1.8, 1.3) ax.legend(loc=9) plt.xlabel("X") plt.ylabel("Field") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.076 seconds) .. _sphx_glr_download_examples_06_exact_values_example_1D.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06_exact_values_example_1D.ipynb <06_exact_values_example_1D.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06_exact_values_example_1D.py <06_exact_values_example_1D.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 06_exact_values_example_1D.zip <06_exact_values_example_1D.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_