簡體   English   中英

使用scipy.interplote.interp1d和matplotlib Python 2.7 32位繪制圓滑曲線(Enthought Canopy)

[英]Plotting smooth curves using scipy.interplote.interp1d and matplotlib Python 2.7 32-bit (Enthought Canopy)

我已經計算出最適合散點圖的曲線,並且希望將結果繪制為平滑曲線,類似於SAS的樣條曲線。

經過一番谷歌搜索之后,它發現在繪制線之前我應該​​先對數據使用interpolate.interp1d。 但是,當我嘗試根據文檔中的教程進行操作時,會出現錯誤。 在此先感謝您的幫助或資源!

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.

您首先不檢查一下數組ij的形狀。 也許您的函數模型會重現不同大小的數組?

我真的應該發表評論,但我有足夠的觀點發表評論...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM