Hi, I am trying to use FigureWidget
with make_subplots
. But I want to initialize an empty plot (go.FigureWidget()
and not go.FigureWidget(make_subplots())
) because the number of rows and cols in the subplot changes based on the selection of my ipywidget. That is to say, that I have a checkbox with events listed and a dropdown of a selection of stocks. Depending on which stock and which Event I select, I need other dimensions in the subplot. Each subplot then gets populated by the selected stock price and its benchmark. The different subplots are for different time periods. It should look like the figure attached. With this code I am able to plot the picture attached. But now I want to update the number of subplots and the data in it based on the checkbox and dropdown.
rets_interesting = extract_interesting_date_ranges(returns.loc[returns[ticker.value].dropna().index], periods)
num_plots = len(rets_interesting)
num_rows = int((num_plots + 1) / 2)
legend_list = [True] + [False] * (len(rets_interesting)-1)
e = go.FigureWidget(make_subplots(rows=num_rows, cols=2, subplot_titles=list(rets_interesting)))
for i, (name, rets_period) in enumerate(rets_interesting.items()):
e.add_trace(go.Scatter(x=ep.cum_returns(rets_period, 1)[ticker.value].index,
y=ep.cum_returns(rets_period, 1)[ticker.value],
line=dict(color=RB_COLOURS[0]),
legendgroup = 'group1',
name = ticker.value,
showlegend = legend_list[i]),
row=int((i+1)/2+0.5),
col=((i+1)%2 if (i+1)%2 == 1 else (i+1)%2+2))
e.add_trace(go.Scatter(x=ep.cum_returns(rets_period, 1)[benchmark].index,
y=ep.cum_returns(rets_period, 1)[benchmark],
line=dict(color=RB_COLOURS[1]),
legendgroup = 'group1',
name = 'Benchmark '+benchmark,
showlegend = legend_list[i]),
row=int((i+1)/2+0.5),
col=((i+1)%2 if (i+1)%2 == 1 else (i+1)%2+2))