1 # spline interpolation and draw image by matplotlib

 from scipy import interpolate
import matplotlib.pyplot as plt #prepare data of globe
x_g = [, , , , , ]
y_g = [,,,,,] x_points=x_g.copy()
y_points=y_g.copy() # spline interpolation
def f(x):
tck = interpolate.splrep(x_points, y_points)
return interpolate.splev(x, tck) # a test point 1.25/ ret=f(1.25)
p1=f(1.25)
print(p1.tolist()) # ndarray to list
x_g.append(1.25)
y_g.append(p1.tolist()) # another test point [2.6,3.1,4.5]/ ret=f(m)
m=[2.6,3.1,4.5]
n=f(m)
print(f(m))
x_g.extend(m)
y_g.extend(n) x_g.sort()
y_g.sort()
plt.plot(x_g,y_g)
plt.gray()
plt.grid(True) # add label for each point
for i in range(,len(x_g)):
plt.text(x_g[i],y_g[i],str([x_g[i],y_g[i]]), family='serif', style='italic', ha='right', wrap=True) plt.show()
05-18 16:35
查看更多