gpt4 book ai didi

python - Matplotlib 从 3 个点绘制样条线

转载 作者:太空宇宙 更新时间:2023-11-03 13:41:38 25 4
gpt4 key购买 nike

我画了 Spline 关注帖子:Matplotlib draw Spline from multiple points

但是当我从 3 个点绘制 Spline

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] ] )

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()

我收到错误

raise TypeError('m > k must hold')
TypeError: m > k must hold

所以,帮我从 3 个点画出 Spline :(

最佳答案

点数 (m) 必须大于样条的次数 (k)。根据documentation ,默认度数为 k = 3。由于您有三个点,因此需要通过更改以下行将度数设置为 2:

tck,u = interpolate.splprep( [x,y], k = 2)

3 point spline

关于python - Matplotlib 从 3 个点绘制样条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29934831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com