[SciPy-dev] gplt suggestion: initcmd

Alan G Isaac aisaac at american.edu
Fri Jul 15 21:11:43 CDT 2005


Here is the figure 3 tutorial.  The existing version called 
asarray_1d, which is apparently defunct.  I did not see why,
so I just deleted that line.

Cheers,
Alan Isaac

PS I'm done for now.



# Cubic-spline
x = arange(0,2*pi+pi/4,2*pi/8)
y = sin(x)
tck = interpolate.splrep(x,y,s=0)
xnew = arange(0,2*pi,pi/50)
ynew = interpolate.splev(xnew,tck,der=0)
pylab.figure(1)
pylab.plot(x,y,'b-x',xnew,ynew,'m',xnew,sin(xnew),'r')
pylab.legend(['Linear','Cubic Spline', 'True'])
pylab.xlim(-0.05,6.33)
pylab.ylim(-1.05,1.05)
pylab.title('Cubic-spline interpolation')
pylab.savefig('interp_cubic.eps')
# Derivative of spline
yder = interpolate.splev(xnew,tck,der=1)
pylab.figure(2)
pylab.plot(xnew,yder,'b-',xnew,cos(xnew),'r--')
pylab.legend(['Cubic Spline', 'True'])
pylab.xlim(-0.05,6.33)
pylab.ylim(-1.05,1.05)
pylab.title('Derivative estimation from spline')
pylab.savefig('interp_cubic_der.eps')
# Integral of spline
def integ(x,tck,constant=-1):
	out = zeros(x.shape, x.typecode())
	for n in xrange(len(out)):
		out[n] = interpolate.splint(0,x[n],tck)
	out += constant
	return out
yint = integ(xnew,tck)
pylab.figure(3)
pylab.plot(xnew,yint,'b-',xnew,-cos(xnew),'r--')
pylab.legend(['Cubic Spline', 'True'])
pylab.xlim(-0.05,6.33)
pylab.ylim(-1.05,1.05)
pylab.title('Integral estimation from spline')
pylab.savefig('interp_cubic_int.eps')
# Roots of spline
print interpolate.sproot(tck)
# [ 0. 3.1416]
# Parametric spline
t = arange(0,1.1,.1)
x = sin(2*pi*t)
y = cos(2*pi*t)
tck,u = interpolate.splprep([x,y],s=0)
unew = arange(0,1.01,0.01)
out = interpolate.splev(unew,tck)
pylab.figure(4)
pylab.plot(x,y,'b-x',out[0],out[1],'m',sin(2*pi*unew),cos(2*pi*unew),'r')
pylab.legend(['Linear','Cubic Spline', 'True'])
pylab.xlim(-1.05,1.05)
pylab.ylim(-1.05,1.05)
pylab.title('Spline of parametrically-defined curve')
pylab.savefig('interp_cubic_param.eps')
pylab.show()






More information about the Scipy-dev mailing list