我們在前幾篇上有提到,跟著大師Finlab學習裏頭,了解了怎麼爬股市資訊

現在結合"python-在colaboratory-上頭運行,新手的好工具" 裏頭教的如何爬取股市資訊

再結合Plotly的功能,來繪製K線圖

d = {'Symbol': ['2330.TW', '2409.TW', '6116.tw'], 'Name': ['TSMC', 'AUO', 'HannStar']}

tw_index= pd.DataFrame(data=d)

import time
## 改成台股index
tw_index_history = {}
for symbol, name in zip(tw_index['Symbol'], tw_index['Name']):
    
    print(name)
    
    tw_index_history[name] = crawl_price(symbol, 365*10)
    time.sleep(1)

### 以下Testing ok inJupyter  2020/11/22
from plotly.offline import plot, iplot, init_notebook_mode
import plotly.graph_objs as go

init_notebook_mode()
for i in tw_index_history:
    layout = go.Layout(height=800, width=1000, title=i)
    trace = go.Candlestick(x=tw_index_history[i].index,
                           open=tw_index_history[i].open,
                           high=tw_index_history[i].high,
                           low=tw_index_history[i].low,
                           close=tw_index_history[i].close)
    data = [trace]
    iplot(data, filename='simple_candlestick')

而且可以次會好多個

Plotly的好處是繪圖後,在網頁的架構下,可以自行的x-asis,y-asis等,可以提供使用者互動的使用

藉由滑鼠的選取,自由的zoom in/out去檢查圖表,還蠻方便的,可惜的是無法在spyder上顯示

TSMC

image

image

AUO

image

HanStar

image

回到目錄

arrow
arrow
    文章標籤
    Python Plotly 台股 K線圖
    全站熱搜
    創作者介紹
    創作者 Cheng yichung 的頭像
    Cheng yichung

    YiChung's space

    Cheng yichung 發表在 痞客邦 留言(0) 人氣()