I have array points
nodes = [(1, 2), (6, 15), (10, 6), (10, 3), (3, 7)]
And now, I need draw Spline
passing through the points. You can see image result
But I don't know how to draw with matplotlib.pyplot
. Help me
So , the right piece of code is:
from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
nodes = np.array( [ [1, 2], [6, 15], [10, 6], [10, 3], [3, 7] ] )
x = nodes[:,0]
y = nodes[:,1]
tck,u = interpolate.splprep( [x,y] ,s = 0 )
xnew,ynew = interpolate.splev( np.linspace( 0, 1, 100 ), tck,der = 0)
plt.plot( x,y,'o' , xnew ,ynew )
plt.legend( [ 'data' , 'spline'] )
plt.axis( [ x.min() - 1 , x.max() + 1 , y.min() - 1 , y.max() + 2 ] )
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With