To control subplot with plotly express

Viewed 36
import plotly.express as px
from plotly.subplots import make_subplots

tips= px.data.tips()

fig = make_subplots(rows=1,cols=2,shared_yaxes=True)

bar1 = px.bar(tips, x="sex", y="total_bill",
             color='smoker',
             barmode ='group',title = 'Group')

bar2= px.bar(tips, x="sex", y="total_bill",
             color='smoker',
             barmode ='stack',title = 'Relative')

bar2.update_traces(showlegend=False)
fig.add_trace(bar1.data[0],row=1,col=1)
fig.add_trace(bar1.data[1],row=1,col=1)
fig.add_trace(bar2.data[0],row=1,col=2)
fig.add_trace(bar2.data[1],row=1,col=2)

enter image description here

I made a bar graph with a plotly express, one with a 'group type' and the other with a 'stack type'. I want to subplot this, but there's no way to express stacks (overlay as well) and do you have any advice here?

0 Answers
Related