How to fix color of bar chart in barmode = group

Hi,
I have a bar chart with barmode=group, it updates every 10 seconds, and the color legend is displayed on the right hand side, so far all good.

My point is that the blue color is always representing the high value, red the second, green the third and so on, so if an item was second in ranking, and becomes first, its color will also change, and off course the legend will change as well.

Is there a way to make dash remember the assigned colors and continue to use them for each item? and if a new item is added, it will add a new color and stick it to it.

As you can see from the three images I uploaded, the first one we can see the TCP was the highest (blue) and UDP was second (Red), however when ICMP came, it took the second place and the red color, similarly on the third image, the ICMP became the first and took the blue color, while TCP second (red) and UDP third (green)
BTW, I use color = protocol

Thanks for assistance.
Picture1
Picture2
Picture3

Hi, just to understand: you want to assign a fixed color to a specific variable?

Are you using plotly.express or plotly.graph objects?

There are several way to do this, you could control this while creating the plot or change it afterwards.

Something like this should work, just add one line for each variable with the corresponding name an color.

fig.update_traces(marker_color="red", selector={"name": "TCP"}

Thanks, this is what I was looking for

1 Like