Plotly express bar colour change

Not sure when this functionality was added, for anyone coming here looking for solutions to grouped bar charts, what most people will want in this case is not color_discrete_sequence but instead color_discrete_map. For example:

fig = px.bar(
    df, 
    x='x', 
    y='y', 
    color='z',   # if values in column z = 'some_group' and 'some_other_group'
    color_discrete_map={
        'some_group': 'red',
        'some_other_group': 'green'
    }
)
5 Likes