File:Interpolation lineaire numpy interp trois extrapolations.svg

Summary

Description
Français : Trois manières d'extrapoler avec une méthode linéaire avec Python Numpy :
  • par une valeur constante ;
  • extrapolation périodique ;
  • extrapolation linéaire.
English: Three ways to extrapolate with a linear method with Python Numpy:
  • by a constant value;
  • periodical extrapolation;
  • linear extrapolation.
Date
Source Own work
Author Cdang
 
This plot was created with Matplotlib.
Category:Valid SVG created with Matplotlib#Interpolation%20lineaire%20numpy%20interp%20trois%20extrapolations.svg
import numpy as np
import matplotlib.pyplot as plt

# **********************
# * numpy.interp()     *
# * sans option period *
# **********************

xp = np.linspace(0, 2*np.pi, 5)
yp = np.sin(xp)

x = np.linspace(-2*np.pi, 4*np.pi, 25)

ya = np.interp(x, xp, yp)

fig, liste_axes = plt.subplots(3, 1, constrained_layout=True, figsize=[8,8])

fig.suptitle("Interpolation linéaire")

liste_axes[0].plot(x, ya, "y-")
liste_axes[0].plot(xp, yp, "r+")
liste_axes[0].set_title("numpy.interp()")

yb = np.interp(x, xp, yp, period=2*np.pi)

liste_axes[1].plot(x, yb, "y-")
liste_axes[1].plot(xp, yp, "r+")
liste_axes[1].set_title("numpy.interp(period=2*np.pi)")

finterp = interpolate.interp1d(xp, yp, kind="slinear", fill_value="extrapolate")

x2 = np.linspace(-np.pi, 3*np.pi, 25)
y2 = finterp(x2)

liste_axes[2].plot(x2, y2, "y")
liste_axes[2].plot(xp, yp, "+r")
liste_axes[2].set_title('scipy.interpolate.interp1d(fill_value="extrapolate")')

plt.savefig("interpolation_lineaire_numpy_interp_trois_extrapolations.svg", format="svg")

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Interpolation%20lineaire%20numpy%20interp%20trois%20extrapolations.svg
Category:Self-published work Category:Interpolation Category:Extrapolation Category:Python (programming language)
Category:CC-BY-SA-4.0 Category:Extrapolation Category:Interpolation Category:Python (programming language) Category:Self-published work Category:Valid SVG created with Matplotlib