私はプロットをしようとしています。 x軸では、私はFinalSigmaValues
辞書のキーを見たいと思っていて、y軸には同じ辞書の値を見たいと思っています。私は彼らに滑らかな曲線を描きたい。一方、私はFinalSigmaValues
と同じキーを持つ別の辞書を持っています。だから、私は同じプロットに別の曲線も欲しい。私は次のコードを使用して、多くのエラーを取得しています。1つのグラフに2つの曲線をプロットする
from scipy.interpolate import spline
import matplotlib.pyplot as plt
import numpy as np
import collections
Finalsigma = collections.OrderedDict(sorted(FinalSigmaValues.items()))
P = np.array(Finalsigma.keys())
T = np.array(Finalsigma.values())
xnew = np.linspace(T.min(),T.max(),300)
P_smooth = spline(T,P,xnew)
plt.plot(xnew,P_smooth,color='k')
plt.xlabel('w')
plt.ylabel('First Part of the Objective Function')
plt.show()
あなたがコードで見たように、私は現在、私も心配する「FinalPhiValues」を持って、FinalSigmaValues
をプロットしようとしています。どちらの辞書もlen 1376にあります。
---------------------------------------------------------------------------
LinAlgError Traceback (most recent call last)
<ipython-input-18-2d2343ec9634> in <module>()
4 xnew = np.linspace(T.min(),T.max(),300)
5
----> 6 P_smooth = spline(T,P,xnew)
7
8 plt.plot(xnew,P_smooth,color='k')
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\interpolate\interpolate.pyc in spline(xk, yk, xnew, order, kind, conds)
3010
3011 """
-> 3012 return spleval(splmake(xk,yk,order=order,kind=kind,conds=conds),xnew)
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\interpolate\interpolate.pyc in splmake(xk, yk, order, kind, conds)
2925 # the constraint matrix
2926 B = _fitpack._bsplmat(order, xk)
-> 2927 coefs = func(xk, yk, order, conds, B)
2928 return xk, coefs, order
2929
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\interpolate\interpolate.pyc in _find_smoothest(xk, yk, order, conds, B)
2622 tmp = dot(V2.T,A)
2623 Q = dot(tmp,V2)
-> 2624 p = scipy.linalg.solve(Q, tmp)
2625 tmp = dot(V2,p)
2626 tmp = np.eye(N+K) - tmp
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\linalg\basic.pyc in solve(a, b, sym_pos, lower, overwrite_a, overwrite_b, debug, check_finite)
101 return x
102 if info > 0:
--> 103 raise LinAlgError("singular matrix")
104 raise ValueError('illegal value in %d-th argument of internal gesv|posv' %
105 -info)
LinAlgError: singular matrix
また、私が試した:
from scipy.interpolate import spline
import matplotlib.pyplot as plt
import numpy as np
import collections
Finalsigma = collections.OrderedDict(sorted(FinalSigmaValues.items()))
Finalphi = collections.OrderedDict(sorted(FinalPhiValues.items()))
from scipy.interpolate import interp1d
x = Finalsigma.keys()
y = Finalsigma.values()
f = interp1d(x, y)
f2 = interp1d(x, y, kind='cubic')
xnew = Finalphi.values()
plt.plot(x, y, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--')
plt.show()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-37-51a1312588ca> in <module>()
14
15 xnew = Finalphi.values()
---> 16 plt.plot(x, y, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--')
17 plt.show()
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\interpolate\polyint.pyc in __call__(self, x)
77 """
78 x, x_shape = self._prepare_x(x)
---> 79 y = self._evaluate(x)
80 return self._finish_y(y, x_shape)
81
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\interpolate\interpolate.pyc in _evaluate(self, x_new)
586 y_new = self._call(self, x_new)
587 if not self._extrapolate:
--> 588 below_bounds, above_bounds = self._check_bounds(x_new)
589 if len(y_new) > 0:
590 # Note fill_value must be broadcast up to the proper size
C:\Users\administrater\Anaconda2\lib\site-packages\scipy\interpolate\interpolate.pyc in _check_bounds(self, x_new)
618 "range.")
619 if self.bounds_error and above_bounds.any():
--> 620 raise ValueError("A value in x_new is above the interpolation "
621 "range.")
622
ValueError: A value in x_new is above the interpolation range.
を試していけない理由は十分説明的ではありません。正確なエラーメッセージを入力してください。それらをコードとしてフォーマットすることを忘れないでください。 – ForceBru
申し訳ありません、それを忘れてしまいました。今、追加されます。 – user8028576