Black Lives Matter. Please consider donating to Black Girls Code today.

How to prevent axis rescale when trace hidden

I have a graph with multiple traces. When you click a trace in the legend to hide it or double click to hide all the other traces, the graph axes rescale their limits based on the trace(s) still visible. I would like to prevent this behavior. I still wish to allow panning, zooming, etc…

Hi @millercommamatt, if you set explicitely the range of axis as below then the axis won’t change when hiding traces in the legend

import plotly.graph_objects as go
fig = go.Figure()
fig.add_scatter(x=[1, 3], y=[5, 4])
fig.add_scatter(x=[1, 10], y=[5, 4])
fig.update_layout(xaxis_range=(0, 11))
fig.show()

Is there really no other solution than to loop through 20+ traces to find the absolute minimum and maximum values?