2

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.

Sander van den Oord
  • 8,735
  • 2
  • 38
  • 70
Marielle
  • 53
  • 1
  • 5

1 Answers1

5

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.

DapperDuck
  • 2,460
  • 1
  • 7
  • 20