我正在尝试绘制一个 3 子图 PlotLy 图。从上到下:烛台、法线图、法线图。
这是我的代码:
def chart_strategy(df):
# Initialize figure with subplots
fig = make_subplots(rows=3, cols=1)
fig.add_trace(go.Figure( data = [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)
return fig
我收到以下错误:
ValueError:
Invalid element(s) received for the 'data' property of
Invalid elements include: [Figure({
'data': [{'close': array([120.88, 120.93, 120.72, ..., 116.23, 115.78, 115.63]),
'high': array([121.31, 121.2 , 121.11, ..., 116.86, 116.43, 115.73]),
'low': array([120.8 , 120.79, 120.48, ..., 115.94, 115.68, 115.32]),
'open': array([121. , 120.81, 120.92, ..., 116.36, 116.23, 115.71]),
'type': 'candlestick',
'x': array([datetime.datetime(2019, 7, 19, 0, 0),
datetime.datetime(2019, 7, 22, 0, 0),
datetime.datetime(2019, 7, 23, 0, 0), ...,
datetime.datetime(2020, 5, 12, 0, 0),
datetime.datetime(2020, 5, 13, 0, 0),
datetime.datetime(2020, 5, 14, 0, 0)], dtype=object)}],
'layout': {'template': '...'}})]
我尝试只单独绘制烛台图表并且效果很好所以我很漂亮它与行和列部分有关,只是不确定接下来要搜索什么。
我使用以下资源编写此代码: https ://plotly.com/python/table-subplots/ https://plotly.com/python/candlestick-charts/
慕娘9325324
相关分类