3

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
  • 10,986
  • 5
  • 51
  • 96
Marielle
  • 63
  • 1
  • 5

1 Answers1

6

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,728
  • 1
  • 9
  • 21