Chart and Legend colors don't match

Hi! I’m new to plotly and trying to do a stacked graph using data from a csv file.

I found some code that made me happy with the design of this graph (on x axis: No, Yes(made up of three sub sections) but now I’m having trouble getting the colors of the graph and legend to match up.

Data should look like this rn

Column 1 Column 2 Column 3 Column 4
sometimes yes
rarely yes
never no
often yes

Code:

dff = (df.groupby(
    ['Food_Taking_YN', 'Food_Taking'])
    ['Responder_Number'].count().reset_index(drop=0).rename(
    columns={'Responder_Number': 'Count'}))
Food_Taking = px.bar(
    dff,
    x = "Food_Taking_YN",
    y = "Count",
    color = "Food_Taking",
    barmode = "overlay",
)

Thanks!

Capture d’écran 1

The bars can be stacked, overlay, or grouped, but since you have specified overlay, the transparency is automatically applied so that each color can be distinguished. As a result, the colors do not match the colors in the legend. Therefore, either change the barmode to relative (the default) or do not specify a barmode.

# barmode = "overlay",
barmode = "relative",