Open
Description
Problem:
The fig has two xaxises, when toggled trace2, the range of xaxis1 was changed.
Feature request:
How to keep the range of xaxis1 like xaxis2 when toggle trace2?
Video.mp4
Code:
import plotly.graph_objects as go
fig = go.Figure()
x1 = [0, 1, 2, 3, 4, 5]
x2 = [100, 200, 300, 400, 500, 600]
fig.add_trace(
go.Scatter(
x=x1,
y=[7] * 6,
visible=False,
)
)
fig.add_trace(
go.Bar(
x=[0, 1, 2],
y=[1, 2, 3],
)
)
fig.add_trace(
go.Bar(
x=[3, 4, 5],
y=[4, 5, 6],
)
)
# data3
fig.add_trace(
go.Scatter(
x=x2,
y=[8] * 6,
)
)
# create xaxis2
fig.update_layout(
xaxis2={
"anchor": "y",
"side": "top",
"overlaying": "x",
},
)
# Re-assign scatter traces to axes created above
fig.data[3].update(xaxis="x2")
fig.show()