Horizontal bar chart, color dictionary

Hi there

I have adapted a line plot color dictionary syntax in the hope that it would work for a horizontal bar plot - but unfortunately it doesnt. Can anybody tell me how to use a dictionary to colour the bars?

I also want the order to be longest bar at the top (as the order specified here) - but it reverses it for some reason?

thanks a lot

import plotly.graph_objects as go

colordict={‘www.sat’: ‘orange’,
‘www.pr’: ‘purple’,
‘payments.p’: ‘violet’,
‘www.pro’: ‘green’,
‘www.prov’: ‘lightgreen’,
‘www.v’: ‘blue’,
‘www.c’: ‘aqua’,
‘www.a’: ‘brown’,
‘ork’: ‘goldenrod’}

fig = go.Figure(go.Bar(
y= [‘www.sat’,


Hi @michaelk

The following fig definition works:

fig = go.Figure(go.Bar(
                    y= ['www.sat',
                    marker_color = list(colordict.values())))

color_discrete_map is not a property for go.Bar. Hence it is sufficient to define a list of colors, instead of a dict. In the code above I extracted that list from the colordict definition.

Hi @empet
Thanks - colors work great!
I still have the widest bar at the bottom though - is there a way to reverse the order - so 232 is at the top?
thanks for your help

Hi @michaelk

Reverse yaxis as follows:


thanks @empet - all good!