1
我按照this question以下數據給出的建議是:情節光滑曲線在PyPlot與大Y值
import matplotlib.pyplot as plt
from numpy import array, linspace
from scipy.interpolate import spline
xdata = array([25, 36, 49])
ydata = array([145247, 363726, 789055])
xnew = linspace(xdata.min(),xdata.max(),300)
ysmooth = spline(xdata,ydata,xnew)
plt.plot(xnew,ysmooth)
plt.show()
雖然它工作正常,在這個問題的數據,由於某種原因,這個數據,它打破:
Traceback (most recent call last):
File "test.py", line 526, in <module>
ysmooth = spline(xdata,ydata,xnew)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 809, in spline
return spleval(splmake(xk,yk,order=order,kind=kind,conds=conds),xnew)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 771, in splmake
coefs = func(xk, yk, order, conds, B)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/interpolate/interpolate.py", line 500, in _find_smoothest
p = np.dual.solve(Q,tmp)
File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-packages/scipy/linalg/basic.py", line 70, in solve
raise LinAlgError("singular matrix")
numpy.linalg.linalg.LinAlgError: singular matrix
我該如何解決這個問題?這似乎是非常簡單的算法適合的數據。
有趣。我在Mac上使用最新的Enthought安裝。 –
我想我不得不在這種情況下去。我花了太多時間讓這張圖看起來已經正確。 –
其實'2p度'np.polyfit'結束了工作和擬合甚至比這更好。所以我想這一切都很好。 –