Jacob Hibner
Jacob Hibner

Reputation: 1

Plotly Express Using a Button to Update X and Y axis data for boxplot

Can anyone help me use a button to switch the data displayed on the graph? I am trying to change the data to show only Times from specific months. When I plot the graph with the buttons, the data does not change properly and the box plots show everyone having the same minimum time.

box_fig = px.box(mini_dt_cln, x='User', y='Time', color='User',
                 title = 'Interactive NYT Mini Leaderboard BoxPlot')

box_fig.update_layout(
    updatemenus=[
        dict(
            type='buttons',
            direction='right',
            x=0.7, y=1.2,
            showactive=True,
            buttons=list(
                [
                    dict(label='All Months', method='update', visible=True,
                         args=[
                             {'x': [mini_dt_cln['User']]},
                             {'y': [mini_dt_cln['Time']]}
                             
                             ],
                         ),
                    dict(label='January', method='update', visible=True,
                         args=[
                             {'y': [mini_dt_cln[mini_dt_cln['Month']=='January']['Time']]},
                             {'x': [mini_dt_cln[mini_dt_cln['Month']=='January']['User']]}
                             
                             ],
                         ),
                    dict(label='February', method='update', visible=True,
                         args=[
                             {'y': [mini_dt_cln[mini_dt_cln['Month']=='February']['Time']]},
                             {'x': [mini_dt_cln[mini_dt_cln['Month']=='February']['User']]}
                             
                             ],
                         ),]),)])

box_fig.show()

I was expecting the boxplot to show only times from February when I click on the February button and only January when I click on the January button. The boxplot does not update properly and doesn't split data by user either. The regular boxplot works fine, the buttons do not work.

Upvotes: 0

Views: 20

Answers (0)

Related Questions