LoginSignup
14

More than 5 years have passed since last update.

plotly + Jupyterでローソク足

Posted at

bokehと比べてあまりメジャーじゃないplotly。
plotlyはオンライン上のツールだと思われているフシがあるので、localな環境でJupyter上にローソク足を描画してみる。

以下、全てJupyter notebook上から実施

from plotly.offline import init_notebook_mode, iplot
from plotly.tools import FigureFactory as FF
import pandas as pd
try:    
    import Quandl as quandl
except ImportError:
    import quandl as quandl

plotly.offlineというのがあるので、これをインポートするとオフライン上でplotlyが使えるようになる。
今回のデータはQuandlから引っ張ってくるが、なぜか環境によっては最初のQが大文字だったり小文字だったりするので、苦肉の策。(対策がわかる方教えてください)

# jupyter上に描画するためのおまじない
init_notebook_mode()

# Quadlから日経平均株価をDataframeで取得
df = quandl.get("NIKKEI/INDEX")

# ローソク足を描画
fig = FF.create_candlestick(df['Open Price'], df['High Price'], df['Low Price'], df['Close Price'], dates=df.index)
iplot(fig)

結果はこんな感じに↓

newplot.png

実際にJupyterで実行してグラフにカーソルを合わせると四本値が表示される。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14