Yaxis 2 is overlaying its data on yaxis. How do i seperate them?

Hey all,

Im banging my head againstb a brick wall here. I have a graph that displays my data but unfortunately it uses two different scales ms and s. If I have barmode=β€˜group’ it displays the grouped bar chart fine

What I actually want is to display it with a secondary y axis, but when I do this it displays as follows

I realise it is displaying yaxis2 directly centered on yaxis, but I cant see how to uncover then.

i have played around with overlaying, anchor and position but nothing seems to work

can anyone assist?

metric = 'Load Duration (ms)'

fig = go.Figure()

fig.add_trace(go.Bar(
    x=dt_df['Model Name'],
    y=dt_df[metric],
    name='Desktop',
    marker_color=dt_color,
    text=dt_df[metric],
    textposition='outside',
    yaxis='y1'
))

fig.add_trace(go.Bar(
    x=lt_df['Model Name'],
    y=lt_df[metric],
    name='Laptop',
    marker_color=lt_color,
    text=lt_df[metric],
    textposition='outside',
    yaxis='y2'
))

fig.update_layout(
    title=f'Comparison of Load Duration between Desktop (ms) and Laptop (s)',
    xaxis_title='Model',
    yaxis=dict(
        title='Desktop ' + metric.capitalize(),
        titlefont=dict(color=dt_color),
        tickfont=dict(color=dt_color),
        domain=[0, 0.8]  # Adjust the domain of the primary y-axis
    ),
    yaxis2=dict(
        title='Laptop Load Duration (s)',
        titlefont=dict(color=lt_color),
        tickfont=dict(color=lt_color),
        overlaying='y',
        side='right',
        anchor='free',  # Set the anchor to 'free'
        position=1   # Adjust the position of the secondary y-axis
    )
)


fig.show()

If you set an offset group, it will be as intended. Set offsetgroup=1 for the first bar and offsetgroup=2 for the next bar. Please refer to this answer.