Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. from scipy.interpolate import Akima1DInterpolator as Akima
  2. from scipy.interpolate import PchipInterpolator as pchip
  3. from scipy.interpolate import CubicSpline as cubic
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6.  
  7. plt.ion()
  8. np.random.seed()
  9.  
  10. def show_plot(x, y):
  11. p = pchip(x, y)
  12. c = cubic(x, y, bc_type='natural')
  13. c2 = cubic(x, y)
  14. a = Akima(x, y)
  15.  
  16. xp = np.sort(x[0] + (x[-1] - x[0])*np.random.random(200))
  17.  
  18. plt.plot(x, y, 'b+', ms=8, mec='r')
  19. plt.plot(xp, c(xp), 'y-', lw=3, alpha=0.7) # yellow for Cubic/natural
  20. plt.plot(xp, c2(xp), 'y-', lw=3, alpha=0.3) # light-yellow for Cubic/not-a-knot
  21. plt.plot(xp, a(xp), 'b-', lw=2, alpha=0.5) # light-blue for Akima
  22. plt.plot(xp, p(xp), 'm-', lw=1, alpha=1) # red for pchip
  23. plt.draw()
  24.  
  25. x = range(20)
  26. y = 10 * np.sort(np.random.random(20))
  27. show_plot(x, y)
  28.  
  29. x = range(20)
  30. y = 10 * np.random.random(20)
  31. show_plot(x, y)
  32.  
  33. x = 10 * np.sort(np.random.random(20))
  34. y = 10 * np.sort(np.random.random(20))
  35. show_plot(x, y)
  36.  
  37. x = 10 * np.sort(np.random.random(20))
  38. y = 10 * np.random.random(20)
  39. show_plot(x, y)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement