Px.bar color and legend

hi all, I have the following code, im wanting to make a legend like this from

def SetColor(y):
if(y <= 1):
return “red”
elif(y <= 3):
return “yellow”
elif(y <= 5):
return “green”
customscale=[[1, “rgb(255, 0, 0)”],
[2, “rgb(255, 0, 0)”],
[3, “rgb(0, 0, 255)”],
[4, “rgb(0, 0, 255)”]]
@app.callback(
Output(component_id=“chart”, component_property=“figure”),
Input(component_id=“option”, component_property=“value”))
def on_option(option):
filtered_df = df[(df[“Class1”]==option) | (df[“Class2”]==option) | (df[“Class3”]==option) | (df[“Class4”]==option) | (df[“Class5”]==option)]
return px.bar(filtered_df, x=filtered_df[“ID”], y=filtered_df[“score”]) #color=dict(list(map(SetColor, filtered_df[‘score’])))) #color_continuous_scale=“Viridis”, range_color=(0, 7))

cannot seem to work this out… can this be done with plotly express??

Okay, i got it woring with , ).update_traces(marker = dict(color=list(map(SetColor, filtered_df[‘Score’]))))

Now, the legend…

def SetColor(y):
if(y <= 1):
return “red”
elif(y <= 2):
return “orange”
elif(y <= 3):
return “yellow”
elif(y <= 4):
return “lightgreen”
elif(y <= 5 | 6):
return “green”
elif(y <= 7):
return “darkgreen”
elif(y <= 8):
return “silver”
elif(y <= 9):
return “gold”

labels = [‘Very low (1)’, ‘Low’, ‘Below average (3)’, ‘Average(4)’, ‘Adverage (5, 6)’, ‘Above average (7)’, ‘High (8)’, ‘Very High (9)’]
colors = {‘Very low (1)’: ‘red’,
‘Low (2)’: ‘orange’,
‘Below average (3)’: ‘yellow’,
‘Average (4)’: ‘lightgreen’,
‘Average (5, 6)’: “green”,
‘Above average (7)’: ‘darkgreen’,
‘High (8)’: ‘silver’,
‘Very High (9)’: ‘gold’}