回答編集履歴

1

2023/10/24 15:32

投稿

melian
melian

スコア21190

test CHANGED
@@ -1,4 +1,3 @@
1
- こんな感じでしょうか。
2
1
  ```python
3
2
  #グラフ1
4
3
  import numpy as np
@@ -59,15 +58,15 @@
59
58
  df['pointpos'] = df.apply(lambda row: pointpos(row), axis=1)
60
59
 
61
60
  # figを定義
62
- fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.05, row_width=[0.2, 0.7], x_title="Date")
61
+ fig = go.Figure(data=[go.Candlestick(x=df['time'],
62
+ open=df['open'],
63
+ high=df['high'],
64
+ low=df['low'],
65
+ close=df['close'])])
63
66
 
64
- fig.add_trace(
65
- go.Candlestick(x=df.index, open=df['open'], high=df['high'], low=df['low'], close=df['close']),
66
- row=2, col=1)
67
-
68
- fig.add_scatter(x=df.index, y=df['pointpos'], mode="markers",
67
+ fig.add_scatter(x=df['time'], y=df['pointpos'], mode="markers",
69
68
  marker=dict(size=5, color="MediumPurple"),
70
- name="pivot", row=2, col=1)
69
+ name="pivot")
71
70
 
72
71
  #グラフ2
73
72
  # 移動平均線
@@ -84,33 +83,19 @@
84
83
  d_obs = [d.strftime("%Y-%m-%d") for d in df['time']]
85
84
  d_breaks = [d for d in d_all.strftime("%Y-%m-%d").tolist() if not d in d_obs]
86
85
 
87
- # Candlestick
88
- fig.add_trace(
89
- go.Candlestick(x=df["time"], open=df["open"], high=df["high"], low=df["low"], close=df["close"], name="OHLC", showlegend=False),
90
- row=1, col=1
91
- )
92
-
93
86
  # SMA
94
- fig.add_trace(go.Scatter(x=df["time"], y=df["SMA25"], name="SMA25", mode="lines"), row=1, col=1)
87
+ fig.add_trace(go.Scatter(x=df["time"], y=df["SMA25"], name="SMA25", mode="lines"))
95
88
 
96
89
  # ボリンジャーバンド
97
90
  fig.add_trace(
98
- go.Scatter(x=df["time"], y=df["2upper"], name="2σ", line=dict(width=1, color="red")),
91
+ go.Scatter(x=df["time"], y=df["2upper"], name="2σ", line=dict(width=1, color="red")))
99
- row=1, col=1
100
- )
101
92
  fig.add_trace(
102
- go.Scatter(x=df["time"], y=df["2lower"], line=dict(width=1, color="red"), showlegend=False),
93
+ go.Scatter(x=df["time"], y=df["2lower"], line=dict(width=1, color="red"), showlegend=False))
103
- row=1, col=1
104
- )
105
94
 
106
95
  fig.add_trace(
107
- go.Scatter(x=df["time"], y=df["3upper"], name="3σ", line=dict(width=1, color="blue")),
96
+ go.Scatter(x=df["time"], y=df["3upper"], name="3σ", line=dict(width=1, color="blue")))
108
- row=1, col=1
109
- )
110
97
  fig.add_trace(
111
- go.Scatter(x=df["time"], y=df["3lower"], line=dict(width=1, color="blue"), showlegend=False),
98
+ go.Scatter(x=df["time"], y=df["3lower"], line=dict(width=1, color="blue"), showlegend=False))
112
- row=1, col=1
113
- )
114
99
 
115
100
  # Layout
116
101
  fig.update_layout(
@@ -122,17 +107,14 @@
122
107
  )
123
108
 
124
109
  # y軸名を定義
125
- fig.update_yaxes(title_text="株価", row=1, col=1)
110
+ fig.update_yaxes(title_text="株価")
126
- fig.update_yaxes(title_text="出来高", row=2, col=1)
127
- fig.update_yaxes(title_text="乖離率", row=3, col=1)
128
111
 
129
112
  # 不要な日付を非表示にする
130
113
  fig.update_xaxes(
131
114
  rangebreaks=[dict(values=d_breaks)]
132
115
  )
133
-
116
+
134
- fig.update_xaxes(rangeslider= {'visible':False}, row=1, col=1)
117
+ fig.update(layout_xaxis_rangeslider_visible=False)
135
- fig.update_xaxes(rangeslider= {'visible':False}, row=2, col=1)
136
118
  fig.show()
137
119
  ```
138
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-10-24/15d034eb-1c1b-430c-916c-90c60a875146.png)
120
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-10-25/caa6ec9a-dad1-443c-91f4-c5cb8b95603c.png)