〇出力グラフ
〇コード
import matplotlib.pyplot as plt
from mpl_finance import candlestick_ohlc
import matplotlib.dates as mdates
import numpy as np
from datetime import datetime
import fix_yahoo_finance as yf
print("fix_yahoo_finance:" +yf.__version__)
df = yf.download("AAPL", start="2019-01-01", end="2019-05-10")
df = df.reset_index()
df['datenum'] = df['Date'].apply(lambda date: mdates.date2num(date.to_pydatetime()))
df = df.set_index('datenum').drop(columns="Date")
fig = plt.figure()
ax = plt.subplot()
numrows = len(df)
ohlc = np.vstack((range(numrows), df.values.T)).T
candlestick_ohlc(ax, ohlc, width=0.8, colorup='g', colordown='r')
offset_mon = (5-mdates.num2date(df.index[0]).weekday())%5
plt.xticks(range(offset_mon,numrows,5), [mdates.num2date(x).strftime("%Y-%m-%d") for x in df.index][offset_mon::5])
ax.grid(True)
ax.set_xlim(-1, numrows)
fig.autofmt_xdate()
〇必要パッケージのインストール
pip install mpl_finance
pip install fix_yahoo_finance --upgrade --no-cache-dir
0 件のコメント:
コメントを投稿