We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minimum Working Example (MWE):
import plotly.graph_objects as go from plotly.subplots import make_subplots # Data option1_x = ['A', 'B', 'C'] option1_y1 = [1, 3, 2] option1_y2 = [2, 4, 3] option2_x = ['B', 'D', 'E'] option2_y1 = [2, 1, 4] option2_y2 = [3, 2, 5] # Create subplots fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("y1", "y2")) # Add traces for option1 fig.add_trace(go.Bar(x=option1_x, y=option1_y1, name="option1_y1"), row=1, col=1) fig.add_trace(go.Bar(x=option1_x, y=option1_y2, name="option1_y2"), row=2, col=1) # Add traces for option2 fig.add_trace(go.Bar(x=option2_x, y=option2_y1, name="option2_y1"), row=1, col=1) fig.add_trace(go.Bar(x=option2_x, y=option2_y2, name="option2_y2"), row=2, col=1) # Initially set option1 visible and option2 invisible for trace in fig.data: trace.visible = False fig.data[0].visible = True # y1 option1 fig.data[1].visible = True # y2 option1 # Add buttons fig.update_layout( updatemenus=[ { "type": "buttons", "buttons": [ { "label": "option1", "method": "update", "args": [ {"visible": [True, True, False, False]}, # Show only option1 traces ] }, { "label": "option2", "method": "update", "args": [ {"visible": [False, False, True, True]}, # Show only option2 traces ] } ], "showactive": True, } ], ) fig.show()
Toggling to option2, we can see the C xaxis entry (from option1) still showing (even with no data for it):
option2
C
option1
This seems to only be an issue with subplots, and when the traces of different options have some xaxis labels in common (in this case B).
B
The text was updated successfully, but these errors were encountered:
One workaround I found is to reset axes by passing "xaxis": {} (and "xaxis2": {}) as second args to buttons, i.e.:
"xaxis": {}
"xaxis2": {}
args
buttons
fig.update_layout( updatemenus=[ { "type": "buttons", "buttons": [ { "label": "option1", "method": "update", "args": [ {"visible": [True, True, False, False]}, # Show only option1 traces { "xaxis": {}, "xaxis2": {}, }, ] }, { "label": "option2", "method": "update", "args": [ {"visible": [False, False, True, True]}, # Show only option2 traces { "xaxis": {}, "xaxis2": {}, }, ] } ], "showactive": True, } ], )
Sorry, something went wrong.
No branches or pull requests
Minimum Working Example (MWE):
Toggling to
option2
, we can see theC
xaxis entry (fromoption1
) still showing (even with no data for it):This seems to only be an issue with subplots, and when the traces of different options have some xaxis labels in common (in this case
B
).The text was updated successfully, but these errors were encountered: