Dual axis Box plot in Plotly using Graph objects

Hi, I am trying to create a Box plot that will have dual y-axis to represent different range of my data. Right now, I am using Graph object library and am able to create the graph.

My code is:

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

fig = make_subplots(specs=[[{"secondary_y": True}]])

fig.add_trace(
    go.Box(
        y= list(df1['Driving distance']),
        x = list(df1['plant']),
        name = 'Distance'
    ),
    secondary_y=False,
)

fig.add_trace(
    go.Box(
        y= list(df1['Production time']),
        x = list(df1['plant']),
        name = 'Time'        
    ),
    secondary_y=True,
)

fig.show()

And resulting figure I am getting looks like this:

Now as can be seen from the graph my two box plots for same states are overlapping with each other, is there any way that I can separate them side by side, so that I can read my graph more easily?

Note: By side-by-side I mean inside this graph, like for OKC two distinct bar plots should be present not a 2 column figure which I know we create easily using plotly.

Thank You

HI @bhavya ,

try this:
fig.update_layout(boxmode='group')

source: How to create Grouped box plot in Plotly? - GeeksforGeeks

1 Like