下午好,我想在这里更改样条曲线中的绿线: 所以,我写了这个:
import numpy as np
import math as m
import matplotlib.pyplot as plt
from scipy import interpolate
x=np.array([-1.51680376, -5.59528478, 3.02763056, 3.99336847,
1.16267044,2.76931318, -0.07837944, 2.16852768, -1.81093278,
1.82262034,-5.47060927, 1.49435114, -7.97536149, 1.05175547,
-4.12788774,0.31526786, -4.4241668 ])
y=np.array([45,45,41.1314913,41,40.25582197,40,39.33855863,39,
38.45406219,38,37.69804062,37,37,36,36,35,35])
tck = interpolate.splrep(x, y)
xnew = np.arange(min(x),max(x), 200)
ynew = interpolate.splev(xnew, tck)
plt.plot(x,y,'g',xnew,ynew)
plt.show()
我在这方面有个问题:
^{pr2}$Python说输入数据有错误,但我不明白为什么。。。在
感谢您的帮助:)
问题是对}依赖于
splrep()
调用中的参数x
没有排序,必须对其排序。^根据文档,{FITPACK
中的curfit
Fortran例程。有关curfit
的代码,请参见https://github.com/scipy/scipy/blob/master/scipy/interpolate/fitpack/curfit.f。在根据
curfit.f
中的评论:也就是说,
x(1)<x(2)<x(3)...
。对于您的数据,此条件不满足。而且,y(x)
是一个多值函数。在相反,我认为您应该尝试匹配}排序-反转:
^{pr2}$x
与y
并保持{相关问题 更多 >
编程相关推荐