1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| import plotly.graph_objects as go
from plotly.subplots import make_subplots
# データ取得
df = yf.download('AAPL', period='1y')
# チャート作成
fig = go.Figure()
# 終値のライン
fig.add_trace(go.Scatter(
x=df.index,
y=df['Close'],
mode='lines',
name='Close Price',
line=dict(color='#1a5f2a', width=2)
))
# 高値・安値のレンジ
fig.add_trace(go.Scatter(
x=df.index,
y=df['High'],
mode='lines',
name='High',
line=dict(color='green', width=1, dash='dash'),
opacity=0.5
))
fig.add_trace(go.Scatter(
x=df.index,
y=df['Low'],
mode='lines',
name='Low',
line=dict(color='red', width=1, dash='dash'),
opacity=0.5
))
# レイアウト設定
fig.update_layout(
title='AAPL Stock Price (Interactive)',
xaxis_title='Date',
yaxis_title='Price (USD)',
hovermode='x unified',
template='plotly_white'
)
# 表示(HTMLとして保存も可能)
fig.show()
fig.write_html('interactive_chart.html')
|