Skip to content

Instantly share code, notes, and snippets.

@ev-br
Created February 18, 2014 22:22
Show Gist options
  • Save ev-br/9081651 to your computer and use it in GitHub Desktop.
Save ev-br/9081651 to your computer and use it in GitHub Desktop.
akima / pchip
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
from scipy.interpolate import pchip, Akima
import numpy as np
# <codecell>
import matplotlib.pyplot as plt
plt.ion()
# <codecell>
np.random.seed(1234)
x = 10 * np.sort(np.random.random(20))
y = 10 * np.sort(np.random.random(20))
p = pchip(x, y)
a = Akima(x, y)
xp = x[0] + (x[-1] - x[0])*np.random.random(200)
xp.sort()
plt.plot(x, y, 'ro', ms=8, mec='r')
plt.plot(xp, p(xp), 'b-', lw=4, alpha=0.6)
plt.plot(xp, a(xp), 'm-', lw=2)
plt.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment