Avoid grouping by color in px.timeline

I’m creating a timeline with px.timeline, and if I don’t set the color, the y-axis shows in the correct order (as I want it):

But when I set up the colors of each of the bars, they group together and change the order:

How do I avoid that? I want the order to be the same as I give in. I have tried fig.update_yaxes(categoryorder="trace") or adding barmode='relative' to the layout, but none of those helped.

Thank you in advance!

Giving this a bump as I’m also having this problem.

Have you found a solution Filipe?

Not exactly, but I found a workaround using barplots directly. I was trying to do these plots with go.Bar, but was having problems with the dates. Then, I tried with px.timeline and had the issue that I described above. Then, I compared the generated html outputs and found how to fix the first, by:

  • adding a type:“date” to the xaxis:
    fig[‘layout’][‘xaxis’].update(dict( type=“date” ))
  • dividing the timedelta by 1 million (seems that the time units are the problem here):

So, my code looks like this:

  fig.add_trace(go.Bar( x=timeline_df['duration']/1000000,
                        name = 'Timeline',

I hope that helps.

I have also posted about this here.

I got that to work for me! Thanks for your help!

For reference, my code

    fig_delivery = go.Figure()

Great to know! I marked that as a solution now - it’s more a workaround, but it’s an easy enough way to implement.

I have the same issue. But I am not using date value but only numeric. Is there a way to make this work, and avoid grouping by color but keep the initial grouping ?

Have you tried to use the go.Bar instead of the px.timeline? If so, could you share a snippet of your code?

Yes, I am using bar type, In fact am I facing the issue with R. Here’s a code snippet:

df = data.frame(
    seed = c(1, 2, 3, 4, 5),
    species = c("bertoniensis", "ovata", "albida", "somae", "ovata")

p<- plot_ly(
        x = df$seed,
        y = 1,
        type = "bar",
        color = df$species,

It is working fine on its own, but used within a subplot it gets grouped together by color.

I don’t know much about R, you seem to be doing as explained here:

But you can also try passing a list to marker.color, as explained here: