Setup Dropdown with two subplot figure

I’m trying to concatenate two figure subplots in Plotly, but I’m encountering issues because the datasets used in the two subplots don’t have the same datetime in the x-axis and layout. Additionally, I’m using widgets to switch between the data subplots.

My ultimate goal is to switch from a dataset to an other thanks to widget label, please find the code here :

fig1 = make_subplots(rows=1, cols=3)
fig1 = tracer_courbes(fig1, 1, DATA_PREVIOUS_A, DATA_PREVIOUS_A_02, DATA_CURRENT_A)

fig2 = make_subplots(rows=1, cols=3)
fig2 = tracer_courbes(fig2, 1, _DATA_PREVIOUS_A, _DATA_PREVIOUS_A_02, _DATA_CURRENT_A)

# Update layout for figure 1
fig1.update_layout(title_text="Subplot 1",
                    showlegend=False)

# Update layout for figure 2
fig2.update_layout(title_text="Subplot 2",
                    showlegend=False)

# Adjust x-axis and y-axis ranges to match each other
fig1.layout.xaxis.update(range=fig2.layout.xaxis.range)
fig1.layout.yaxis.update(range=fig2.layout.yaxis.range)

# Create a dropdown menu to select between figures
dropdown = [
    {'label': 'Subplot 1', 'method': 'update', 'args': [{'visible': [True, True, True]}, {'title': 'Subplot 1'}]},
    {'label': 'Subplot 2', 'method': 'update', 'args': [{'visible': [True, True, True]}, {'title': 'Subplot 2'}]}
]

# Combine the two figures into one
fig = go.Figure(data=fig1.data + fig2.data, layout=fig1.layout)

# Add dropdown menu to switch between figures
fig.update_layout(updatemenus=[{'buttons': dropdown,
                                'direction': 'down',
                                'showactive': True,
                                'x': 0.1,
                                'xanchor': 'left',
                                'y': 1.1,
                                'yanchor': 'top'}])

someone has the right way to do it without dash please ?

Hi @Eng-DATA_FR ,

Can you provide us data samples, which will help us a lot to reproduce your issues.
Thanks.

1 Like