0
분산 형 그래프에 가장 잘 맞는 곡선을 계산 했으므로 결과를 부드러운 곡선으로 표시하고 싶습니다. SAS의 스플라인과 유사합니다.scipy.interplote.interp1d 및 matplotlib를 사용하여 매끄러운 곡선 그리기 Python 2.7 32 비트 (Enthought Canopy)
인터넷 검색을 한 후 선을 그리기 전에 내 데이터에 interpolate.interp1d를 먼저 사용해야한다는 것을 알게되었습니다. 그러나 documentation의 자습서를 기반으로이 작업을 수행하려고하면 오류가 발생합니다. 도움이나 자원에 미리 감사드립니다!
from scipy import interpolate
j = np.arange(0, 29, 1) # new x values
k = (model(xdata, g_fit, a_fit, b_fit)) # y values
l = interpolate.interp1d(j, k)
plt.scatter(xdata, ydata, c='g', marker='x')
plt.plot(xdata, model(xdata, g_fit, a_fit, b_fit), color='red')
plt.plot(j, l(k))
plt.axis([-1, 31, 0.5, 1.2]) # xmin, xmax, ymin, ymax
plt.show()
print p
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-56-0db707080a49> in <module>()
2 j = np.arange(0, 29, 1)
3 k = (model(xdata, g_fit, a_fit, b_fit))
----> 4 l = interpolate.interp1d(j, k)
5
6 plt.scatter(xdata, ydata, c='g', marker='x')
C:\Enthought\Canopy32\User\lib\sitepackages\scipy\interpolate\
interpolate.py in __init__
(self, x, y, kind, axis, copy, bounds_error, fill_value)
331 copy=True, bounds_error=True, fill_value=np.nan):
332 """ Initialize a 1D linear interpolation class."""
--> 333 _Interpolator1D.__init__(self, x, y, axis=axis)
334
335 self.copy = copy
C:\Enthought\Canopy32\User\lib\site-packages\scipy\interpolate\
polyint.py in __init__(self, xi, yi, axis)
33 self.dtype = None
34 if yi is not None:
---> 35 self._set_yi(yi, xi=xi, axis=axis)
36
37 def __call__(self, x):
C:\Enthought\Canopy32\User\lib\site-packages\scipy\interpolate\
polyint.py in _set_yi(self, yi, xi, axis)
92 shape = (1,)
93 if xi is not None and shape[axis] != len(xi):
---> 94 raise ValueError("x and y arrays must be equal in length along "
95 "interpolation axis.")
96
ValueError: x and y arrays must be equal in length along interpolation axis.
을 정말 코멘트를 제기해야하지만 게시 코멘트 포인트가 부족 할 각 단계가 무엇을해야하는지 확신하지 못합니다. 각 y 값에 대해 하나의 x 값이 있습니다. – Bprodz
_ValueError 오류 : x 및 y 배열은 보간 axis_를 따라 길이가 동일해야합니다. i와 j는 같은 모양입니다. 그러나 나는 cubic 보간을하기 전에 특정 기능을 가진 ad poblems를 가지고있다. 귀하의 경우에 해당해서는 안됩니다. – ssm