最初に株のグラフ指標を書いた後にビットコインの指標を表したく、株のグラフ指標のコードをコピペしたのですが、次元を同じにする必要があるとエラーが出たのですが。
ご指摘いただきたいです。
よろしくお願いします。
参考動画 問題時点は、19:50分です。
Python
1start = '2017-07-01' 2end = '2020-07-01' 3 4df = data.DataReader('BTC-JPY','yahoo',start,end)
↓
Python
1df.head(30)
↓
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(5,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(5,1,2) 11plt.bar(date,df['Volume'],label='Volumr',color='grey') 12plt.legend() 13 14plt.subplot(5,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(5,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(5,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() 29
Python
1ValueError Traceback (most recent call last) 2<ipython-input-78-7e591daadd7c> in <module> 3 2 plt.subplot(5,1,1) 4 3 5----> 4 plt.plot(date,close,label='Close',color='#99b898') 6 5 plt.plot(date,df['sma01'],label='sma01',color='#e84a5f') 7 6 plt.plot(date,df['sma02'],label='sma02',color='#ff847c') 8 9~/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py in plot(scalex, scaley, data, *args, **kwargs) 10 2809 return gca().plot( 11 2810 *args, scalex=scalex, scaley=scaley, **({"data": data} if data 12-> 2811 is not None else {}), **kwargs) 13 2812 14 2813 15 16~/anaconda3/lib/python3.7/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs) 17 1808 "the Matplotlib list!)" % (label_namer, func.__name__), 18 1809 RuntimeWarning, stacklevel=2) 19-> 1810 return func(ax, *args, **kwargs) 20 1811 21 1812 inner.__doc__ = _add_data_doc(inner.__doc__, 22 23~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py in plot(self, scalex, scaley, *args, **kwargs) 24 1609 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D._alias_map) 25 1610 26-> 1611 for line in self._get_lines(*args, **kwargs): 27 1612 self.add_line(line) 28 1613 lines.append(line) 29 30~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py in _grab_next_args(self, *args, **kwargs) 31 391 this += args[0], 32 392 args = args[1:] 33--> 393 yield from self._plot_args(this, kwargs) 34 394 35 395 36 37~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py in _plot_args(self, tup, kwargs) 38 368 x, y = index_of(tup[-1]) 39 369 40--> 370 x, y = self._xy_from_xy(x, y) 41 371 42 372 if self.command == 'plot': 43 44~/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py in _xy_from_xy(self, x, y) 45 229 if x.shape[0] != y.shape[0]: 46 230 raise ValueError("x and y must have same first dimension, but " 47--> 231 "have shapes {} and {}".format(x.shape, y.shape)) 48 232 if x.ndim > 2 or y.ndim > 2: 49 233 raise ValueError("x and y can be no greater than 2-D, but have " 50 51ValueError: x and y must have same first dimension, but have shapes (1098,) and (245,) 52`` 53 54 55 56![イメージ説明](317864735d07dfc63cc771a6cc807d63.png) 57![イメージ説明](6c6f9b5f0d907e262d3c71831d4d854a.png) 58![イメージ説明](87f7d87e80ab5e5c3106f94881a72d0a.png) 59![イメージ説明](23175f1f3f4368407596120bda328ff2.png)
回答2件
あなたの回答
tips
プレビュー