-
-
Save misho104/46032fa730088a0cb4c2e0556c59260b to your computer and use it in GitHub Desktop.
akima / pchip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.interpolate import Akima1DInterpolator as Akima | |
from scipy.interpolate import PchipInterpolator as pchip | |
from scipy.interpolate import CubicSpline as cubic | |
import numpy as np | |
import matplotlib.pyplot as plt | |
plt.ion() | |
np.random.seed() | |
def show_plot(x, y): | |
p = pchip(x, y) | |
c = cubic(x, y, bc_type='natural') | |
c2 = cubic(x, y) | |
a = Akima(x, y) | |
xp = np.sort(x[0] + (x[-1] - x[0])*np.random.random(200)) | |
plt.plot(x, y, 'b+', ms=8, mec='r') | |
plt.plot(xp, c(xp), 'y-', lw=3, alpha=0.7) # yellow for Cubic/natural | |
plt.plot(xp, c2(xp), 'y-', lw=3, alpha=0.3) # light-yellow for Cubic/not-a-knot | |
plt.plot(xp, a(xp), 'b-', lw=2, alpha=0.5) # light-blue for Akima | |
plt.plot(xp, p(xp), 'm-', lw=1, alpha=1) # red for pchip | |
plt.draw() | |
x = range(20) | |
y = 10 * np.sort(np.random.random(20)) | |
show_plot(x, y) | |
x = range(20) | |
y = 10 * np.random.random(20) | |
show_plot(x, y) | |
x = 10 * np.sort(np.random.random(20)) | |
y = 10 * np.sort(np.random.random(20)) | |
show_plot(x, y) | |
x = 10 * np.sort(np.random.random(20)) | |
y = 10 * np.random.random(20) | |
show_plot(x, y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment