Change color in plotly bar graph

Viewed 3256

How can I change in plotly express the color of a specific bar in a bar graph. For example, I want to change the color to purple , to the German Shephard (from the breed).

fig = px.bar(data_frame=df, x="quantity", y="dogs", orientation='h', color='dogs',hover_name='breed',)

Thanks.

1 Answers

You can make a discrete_color_map dictionary like this:

color_discrete_map = {'German Shephard': 'rgb(255,0,0)'}

And pass it into your parameters when creating the bar chart like this:

fig = px.bar(data_frame=df, x="quantity", y="dogs", orientation='h', color='dogs',hover_name='breed',color_discrete_map = color_discrete_map)

Here is the documentation.

Related