Color_discrete_map not working

Hi Everyone

I’m new to dash and Im trying to create a bar chart wich highlights specific bars based on there id’s

def update_plot(dropdown_value):
    dff = df
    labels = df.institution_id
    data = df[dropdown_value]
    barchart = px.bar(
        data_frame= dff,
        x= labels,
        y = data,
        title= dropdown_value,
        category_orders={
            "institution_id": [
                81,
                91,
            ]
        },
        barmode="relative",
        opacity=0.9,
        color_discrete_map={
            81: "rgb(31,120,180)",
            91: "rgb(166,206,227)",
        },
    )
    return barchart

Here is my code, but for some reason, color_discrete_map doesn’t seem to work even though I followed the steps given in the documentation

Any help would be appreciated

Thanks

A little late, but you need to specify a color argument otherwise the color_discrete_map doesn’t know what keys to map
e.g.
px.bar(…,
color=…
color_discrete_map=…
)

1 Like