1 回答

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊
問題是您如何添加第一條軌跡。您正在使用:
fig.add_trace(go.Figure( data = [go.Candlestick( x = df.index,...
但它應(yīng)該是:
fig.add_trace(go.Candlestick(x = df.index,...
import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
N=14
df = pd.DataFrame({'Open': np.random.randint(1,29,N),
'Close': np.random.randint(1,29,N),
'Low': np.random.randint(1,29,N),
'High': np.random.randint(1,29,N),
'Action': np.random.choice(['sell', 'buy'],N),
'System Quality Number': np.random.randint(1,29,N)})
def chart_strategy(df):
fig = make_subplots(rows=3, cols=1)
fig.add_trace(go.Candlestick(x = df.index,
open = df['Open'],
close = df['Close'],
low = df['Low'],
high = df['High']),
row = 1, col = 1)
fig.add_trace(go.Scatter(x = df.index, y = df['System Quality Number']),
row = 2, col = 1)
fig.add_trace(go.Scatter(x = df.index, y = df['Action']), row = 3, col =1)
fig.update_xaxes(row=1, col=1, rangeslider_thickness=0.05)
fig.update_layout(width=900, height=900)
return fig
chart_strategy(df)
添加回答
舉報(bào)