Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color in plotly bar graph [duplicate]

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.

like image 321
Marielle Avatar asked Nov 24 '25 21:11

Marielle


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.

like image 178
DapperDuck Avatar answered Nov 26 '25 11:11

DapperDuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!