Plotly subplot how to add timeline trace on the same row with different colors?

When I do fig = px.timeline(df_bubble_bg, x_start="start", x_end="end", y="type", color='ID'), I get a nice event sequence in one row, such as this:

However, when I tried subplot

traces = px.timeline(df_bubble_bg, x_start="start", x_end="end", y="participant", color='ID')
fig = make_subplots(rows=1, cols=1)
for trace in traces.data:
    fig.add_trace(trace, row=1, col=1)

I would expect the same result, but instead, I got this result below:

However, if I remove the color='ID' when creating the trace, I can get them to appear on the same row, but then they all have the same color, which is not desired.
What was missing, what should I adjust in order to get the exact same result without using the subplot. The reason Iā€™m asking is because I have plan to add subplots to the figure, but like to keep that timeline form.

Hi @Peilin !

Try to set fig.update_layout(barmode='overlay').

Hi, thanks for the swift response! I also dug around meanwhile and found that barmode='stack' seems to do the trick as well. Thank you very much!

1 Like