Actualmente estoy trabajando con plotly. Tengo una función llamada plotChart que toma un marco de datos como entrada y traza un gráfico de velas. Estoy tratando de encontrar una manera de pasar una lista de marcos de datos a la función plotChart y usar un menú desplegable para mostrar las opciones en la lista de entrada por el nombre de la acción. El menú desplegable tendrá la lista de marcos de datos y cuando se haga clic en una opción, se actualizará la figura en plotly. a continuación está el código que tengo para trazar un solo marco de datos
def make_multi_plot(df): fig = make_subplots(rows=2, cols=2, shared_xaxes=True, vertical_spacing=0.03, subplot_titles=('OHLC', 'Volume Profile'), row_width=[0.2, 0.7]) for s in df.name.unique(): trace1 = go.Candlestick( x=df.loc[df.name.isin([s])].time, open=df.loc[df.name.isin([s])].open, high=df.loc[df.name.isin([s])].high, low=df.loc[df.name.isin([s])].low, close=df.loc[df.name.isin([s])].close, name = s) fig.append_trace(trace1,1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].BbandsMid, mode='lines',name='MidBollinger'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].BbandsUpp, mode='lines',name='UpperBollinger'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].BbandsLow, mode='lines',name='LowerBollinger'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].vwap, mode='lines',name='VWAP'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].STDEV_1, mode='lines',name='UPPERVWAP'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].STDEV_N1, mode='lines',name='LOWERVWAP'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].KcMid, mode='lines',name='KcMid'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].KcUpper, mode='lines',name='KcUpper'),1,1) fig.append_trace(go.Scatter(x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].KcLow, mode='lines',name='KcLow'),1,1) trace2 = go.Bar( x=df.loc[df.name.isin([s])].time, y=df.loc[df.name.isin([s])].volume, name = s) fig.append_trace(trace2,2,1) # fig.update_layout(title_text=s) graph_cnt=len(fig.data) tr = 11 symbol_cnt =len(df.name.unique()) for g in range(tr, graph_cnt): fig.update_traces(visible=False, selector=g) #print(g) def create_layout_button(k, symbol): start, end = tr*k, tr*k+2 visibility = [False]*tr*symbol_cnt visibility[start:end] = [True,True,True,True,True,True,True,True,True,True,True] return dict(label = symbol, method = 'restyle', args = [{'visible': visibility[:-1], 'title': symbol, 'showlegend': False}]) fig.update(layout_xaxis_rangeslider_visible=False) fig.update_layout( updatemenus=[go.layout.Updatemenu( active = 0, buttons = [create_layout_button(k, s) for k, s in enumerate(df.name.unique())] ) ]) fig.show()Estoy tratando de agregar anotaciones a la figura, será diferente para cada gráfico a continuación, así es como lo configuré para el gráfico único df ['superTrend'] es una columna booleana
for i in range(df.first_valid_index()+1,len(df.index)): prev = i - 1 if df['superTrend'][i] != df['superTrend'][prev] and not np.isnan(df['superTrend'][i]) : #print(i,df['inUptrend'][i]) fig.add_annotation(x=df['time'][i], y=df['open'][i], text= 'Buy' if df['superTrend'][i] else 'Sell', showarrow=True, arrowhead=6, font=dict( #family="Courier New, monospace", size=20, #color="#ffffff" ),)