Hi everyone, I have a problem with plotly.
I am trying to make a candlestick chart using python and plotly,
there are 2 subplots in figure ,
I want to click play button , then subplot1 only need show orginal data (static Candlestick).
and subplot2 show dynamic update.
but when use the animate function is called, so surprised
subplot1 it will clean the chart , the chart is emptyed.
please advise me how to display Candlestick(subplot1 ) from click animate , thanks
import plotly.graph_objects as go
import numpy as np
from plotly.subplots import make_subplots
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = make_subplots(rows=1, cols=2, horizontal_spacing=0.1)
fig.add_trace(go.Candlestick(x=df['Date'],
open=df['AAPL.Open'],
high=df['AAPL.High'],
low=df['AAPL.Low'],
close=df['AAPL.Close']), row=1, col=1)
fig.add_trace(go.Scatter(x=np.arange(10),
y=1+3*np.random.rand(10),
marker_size=6), row=1, col=2) #trace of index 2
frames =[go.Frame(data=[ go.Candlestick(visible=True),
go.Scatter(y=2+3*np.random.rand(10))
],
traces=[0,1]
) for k in range(10)] # define 10 frames
fig.frames=frames
button = dict(
label='Play',
method='animate',
args=[None, dict(frame=dict(duration=50, redraw=False),
transition=dict(duration=0),
fromcurrent=True,
mode='immediate')])
fig.update_layout(updatemenus=[dict(type='buttons',
showactive=False,
buttons=[button] )
],
width=800, height=500)
fig.update_layout(yaxis2_range=[0, 5.5], yaxis2_autorange=False)