Stacked bar chart combined with scatter and 2 y axis barmode = group doesnt work

Hey guys,

im trying to build a Dash Chart combined with 2 bar plots and two Scatter plots in one chart additional with 2 y axis for a better view.

my only problem is to group the 2 bar plots. when i make fig.update_layout(barmode = ‘group’) nothing happen and i dont know why.

here is a picute of my graph where i can see that one bar is behind the other and i dont know how to fix it:

Picture:


and when I dismiss the bar Anzahl you can see the other

and here is the code:
ig.add_trace(go.Bar(x = summe2[monat_week], y = summe2[‘Umsatz’], name=‘Umsatz’), secondary_y = False)
fig.update_layout(title_text = ‘Barchart combined’)
fig.update_yaxes(title_text=“Umsatz”)
fig.update_xaxes(title_text = monat_week)
fig.add_trace(go.Scatter(x = week_x_val, y = anzahl_y_val, mode = ‘lines’, name='durch. Anzahl '+str(year_avg_calc)), secondary_y = True)
hover_data={‘Umsatz’ : ':.2f '}, barmode=‘group’)

    fig.add_trace(go.Scatter(x = week_x_val, y = umsatz_y_val, mode = 'lines', name = 'durch. Umsatz '+str(year_avg_calc) ), secondary_y = False)
    fig.add_trace(go.Bar(x = summe2[monat_week], y = summe2['Anzahl'], name = 'Anzahl'), secondary_y = True)
    fig.update_layout(barmode = 'group')

I hope you can help me.

Thank you in advance.

Greetings Mae

Solved it by my own.

Could you post your solution?

At im not at home. I can later Post my solution. But 2 axis of the same type x or y doesnt work with express at the current state so you have to work with plotly.

Greetings mae

@ wildcatgeo,

here is my solution:

fig = make_subplots(specs=[[{“secondary_y”: True}]]) #to make subplots with different axis possible.
fig.add_trace(go.Bar(x = , y = , name=’’, offsetgroup = 1, marker_color = ‘blue’), secondary_y = False)
fig.add_trace(go.Bar(x = , y = ], name = ‘’, offsetgroup = 2, marker_color = ‘brown’),secondary_y=True)

to select the y axis you need to set secondary_y = true or false and to choose what should be stacked you have to specify Offsetgroups.

so if you have 2 bar plots with different offsetgroups they will be displayed next to each other and not behind. :wink:

and at last:
fig.update_layout(barmode = ‘group’)# and voila

I hope I could help you.

Greetings Mae