Update yaxis range with updatemenus button

@petership

You didn’t give details on the initial xaxes title before update, for each subplot. That’s why I created this example you can modify acccording to your needs:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(rows=1, cols=3)

print(fig.layout)

fig.add_trace(go.Scatter(x=[1,2], y=[3,4]), 1, 1)
fig.add_trace(go.Scatter(x=[1,2], y=[3,4]), 1, 2)
fig.add_trace(go.Scatter(x=[1,2], y=[3,4]), 1, 3)
fig.update_xaxes(title='x')

button1 = dict(method = "relayout",
               args = [{'xaxis.title': 'first x',
                        'xaxis2.title': 'x',
                        'xaxis3.title': 'x'},
                          ],
               label = 'xaxis1')

button2 = dict(method = "relayout",
               args = [{'xaxis.title': 'x',
                        'xaxis2.title': 'second x',
                        'xaxis3.title': 'x'
                           } 
                          ],
               label = 'xaxis2')
button3 = dict(method = "relayout",
               args = [{ 'xaxis.title': 'x',
                         'xaxis2.title': 'x',
                         'xaxis3.title': 'third x'} 
                          ],
               label = 'xaxis3')
fig.update_layout(width=800, height=400,
                 updatemenus=[dict(active=0,
                                   x= -0.25, y=1, 
                                   xanchor='left', 
                                   yanchor='top',
                                   buttons=[button1, button2, button3])
                              ]) 
1 Like