[英]Plotly: adding go.figure() to a subplot fails
已經有 2 個小時了,我在子情節中加入不同的獨特人物時遇到了問題。
知道為什么以下內容不起作用:
# MAIN FIGURE
fig = make_subplots(rows=4, cols=1,
specs=[[{"rowspan": 3}],
[None],
[None],
[{}]])
# sub-FIGURE 1
candlestick = go.Candlestick(x = df.index,
open = df.open_BTC,
high = df.high_BTC,
low = df.low_BTC,
close = df.close_BTC)
# sub-FIGURE 2
# Filter data for conditional above/below 0 fillings
pos = df[i] >= 0
above = np.where(pos, df[i], np.nan)
below = np.where(pos, np.nan, df[i])
scatter1 = go.Scatter(x=df.index, y=below, fill='tozeroy')
scatter2 = go.Scatter(x=df.index, y=above, fill='tozeroy')
#... and other cool shit (but must be in fig2 only !)
fig2 = go.Figure(data=[scatter1, scatter2]) # <-- THIS PLOTS WELL !
# ADDING fig1 and fig2 IN SUBPLOT
fig.add_trace(candlestick, row=1, col=1)
fig.add_trace(fig2, row=4, col=1) # <-- THIS DOESN'T WORK... WHY ?
顯然,我不明白如何正確初始化數字。 在此先感謝您的幫助。
在這里誤解,因為沒有這樣的事情。
我可以通過以下方式實現:
fig = make_subplots(rows=4, cols=1,
specs=[[{"rowspan": 3}],
[None],
[None],
[{}]])
candlestick = go.Candlestick(x = df.index,
open = df.open_BTC,
high = df.high_BTC,
low = df.low_BTC,
close = df.close_BTC)
# Filter data
pos = df[i] >= 0
above = np.where(pos, df[i], np.nan)
below = np.where(pos, np.nan, df[i])
scatter1 = go.Scatter(x=df.index, y=below, fill='tozeroy')
scatter2 = go.Scatter(x=df.index, y=above, fill='tozeroy')
#fig2 = go.Figure(data=[scatter1, scatter2])
fig.add_trace(candlestick, row=1, col=1)
fig.add_trace(scatter1, row=4, col=1) # <-- just add the elements at the correct place
fig.add_trace(scatter2, row=4, col=1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.