Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement