擅长:python、mysql、java
<p>您需要采用参数化方法,如下所示:</p>
<p><img src="https://i.stack.imgur.com/zizSa.png" alt="enter image description here"/></p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
points = [(3.28,0.00),(4.00,0.50),(4.40,1.0),(4.60,1.52),(5.00,2.5),(5.00,3.34),(4.70,3.8)]
points = points + [(4.50,3.96),(4.20,4.0),(3.70,3.90),(3.00,3.5),(2.00,2.9)]
data = np.array(points)
tck,u = interpolate.splprep(data.transpose(), s=0)
unew = np.arange(0, 1.01, 0.01)
out = interpolate.splev(unew, tck)
plt.figure()
plt.plot(out[0], out[1], color='orange')
plt.plot(data[:,0], data[:,1], 'ob')
plt.show()
</code></pre>
<p>这基本上是根据<a href="https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html#spline-interpolation-in-1-d-procedural-interpolate-splxxx" rel="nofollow noreferrer">here</a>一节中的最后一个示例重新编写的。</p>