Jupyter lab にて、株のグラフ指標を勉強しているのですが、
以下のエラーコードはどこのコードを追加、もしくは書き換えればエラーが出なく出来るでしょうか。
ご教授お願いします。
Python
1start = '2020-01-01' 2end = '2020-07-01' 3 4df = data.DataReader('DEXJPUS', 'fred', start, end)
df.head(20)
Python
1df=df.rename(columns={'DEXJPUS':'Adj Close'})
Python
1df = df.dropna()
Python
1df.head(20)
Python
1date=df.index 2Close=df['Adj Close'] 3 4span01=5 5span02=25 6span03=50 7 8df['sma01'] = Close.rolling(window=span01).mean() 9df['sma02'] = Close.rolling(window=span02).mean() 10df['sma03'] = Close.rolling(window=span03).mean() 11df['macd'], df['macdsignal'], df['macdhist'] = ta.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9) 12df['RSI'] = ta.RSI(close, timeperiod=span02) 13df["upper"], df["middle"], df["lower"] = ta.BBANDS(close, timeperiod=span02, nbdevup=2, nbdevdn=2, matype=0)
Python
1plt.figure(figsize=(30, 15)) 2plt.subplot(3,1,1) 3 4plt.plot(date,close,label='Close',color='#99b898') 5plt.plot(date,df['sma01'],label='sma01',color='#e84a5f') 6plt.plot(date,df['sma02'],label='sma02',color='#ff847c') 7plt.plot(date,df['sma03'],label='sma03',color='#feceab') 8plt.legend() 9 10plt.subplot(3,1,2) 11plt.bar(date,df['Volume'],label='Volume',color='grey') 12plt.legend() 13 14plt.subplot(3,1,3) 15plt.fill_between(date, df['macdhist'], color = 'grey', alpha=0.5, label='MACD_hist') 16plt.hlines(0,start,end,"gray",linestyles="dashed") 17plt.legend() 18 19plt.subplot(3,1,4) 20plt.plot(date,df['RSI'],label='RSI',color="gray") 21plt.ylim(0, 100) 22plt.hlines([30,50,70],start,end,"gray",linestyles="dashed") 23plt.legend() 24 25plt.subplot(3,1,5) 26plt.plot(date,Close,label='Close',color='#99b898') 27plt.fill_between(date, df["upper"], df["lower"], color="gray", alpha=0.3) 28plt.legend()
↓
Python
1ValueError Traceback (most recent call last) 2<ipython-input-177-309b96a7a5ee> in <module> 3 17 plt.legend() 4 18 5---> 19 plt.subplot(3,1,4) 6 20 plt.plot(date,df['RSI'],label='RSI',color="gray") 7 21 plt.ylim(0, 100) 8 9~/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py in subplot(*args, **kwargs) 10 1082 11 1083 fig = gcf() 12-> 1084 a = fig.add_subplot(*args, **kwargs) 13 1085 bbox = a.bbox 14 1086 byebye = [] 15 16~/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py in add_subplot(self, *args, **kwargs) 17 1365 self._axstack.remove(ax) 18 1366 19-> 1367 a = subplot_class_factory(projection_class)(self, *args, **kwargs) 20 1368 self._axstack.add(key, a) 21 1369 self.sca(a) 22 23~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_subplots.py in __init__(self, fig, *args, **kwargs) 24 58 raise ValueError( 25 59 ("num must be 1 <= num <= {maxn}, not {num}" 26---> 60 ).format(maxn=rows*cols, num=num)) 27 61 self._subplotspec = GridSpec( 28 62 rows, cols, figure=self.figure)[int(num) - 1] 29 30ValueError: num must be 1 <= num <= 3, not 4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。