python3にて、matplotlib.pyplotを使ってローソク足チャートを作成しました。
同じ画像に移動平均線を追記しようとしてエラーとなっております。
fig = plt.figure(figsize=(8, 12), facecolor='#101010') ax1 = fig.add_subplot(211, facecolor='#cccccc') ax2 = fig.add_subplot(212, facecolor='#bbbbbb') ax1.set_title('chart :'+pair , color='#000000') ax1.grid() ax2.set_title('RSI' , color='#000000') ax2.grid() mpf.candlestick2_ochl(ax1, opens=hist1min['oMid'], closes=hist1min['cMid'], highs=hist1min['hMid'], lows=hist1min['lMid'], width=0.5, colorup='k', colordown='r', alpha=0.75) ax1.plot(hist1min.index, hist1min['up2000']) ## error ##ax1.plot(hist1min.index, hist1min['cMid'].rolling(4).mean()) ax1.set_xticklabels([(hist1min.index[int(x)].strftime("%H:%M") if x < hist1min.shape[0] else x) for x in ax1.get_xticks()], rotation=30) ax2.set_xticklabels([(hist1min.index[int(x)].strftime("%H:%M") if x < hist1min.shape[0] else x) for x in ax2.get_xticks()], rotation=30) bottom, top = ax1.get_ylim() ax1.set_ylim(bottom - (top - bottom) / 4, top) ax1b = ax1.twinx() volume_overlay(ax1b, hist1min['oMid'], hist1min['cMid'], hist1min['tickqty'], width=0.5, colorup="g", colordown="g") ax1b.set_ylim([0, hist1min['tickqty'].max() * 4]) ax1b.set_ylabel('volume') with plt.style.context('grayscale'): plt.savefig('zzz_graph.png' , transparent=False) plt.close()
上記の ## error ## でコメントアウトした箇所を入れないとグラフが作れるのですが、コメント部分を実行すると以下エラーとなります。
Traceback (most recent call last): File "05_gazo.py", line 463, in <module> getLast(cnt) File "05_gazo.py", line 243, in getLast ax1.set_xticklabels([(hist1min.index[int(x)].strftime("%H:%M") if x < hist1min.shape[0] else x) for x in ax1.get_xticks()], rotation=30) File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 3191, in get_xticks return self.xaxis.get_ticklocs(minor=minor) File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/axis.py", line 1329, in get_ticklocs return self.major.locator() File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/dates.py", line 1249, in __call__ self.refresh() File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/dates.py", line 1269, in refresh dmin, dmax = self.viewlim_to_dt() File "/usr/bin/.pyenv/versions/3.6.5/lib/python3.6/site-packages/matplotlib/dates.py", line 1026, in viewlim_to_dt .format(vmin)) ValueError: view limit minimum -36854.15829861111 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units
以下サイトを参考に作っているのですが、回避方法が見つかりません。
https://note.nkmk.me/python-pandas-matplotlib-candlestick-chart/
お手数ですが、解決策が分かるようでしたらご教授頂けると助かります。
よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。