So, I want to create a bar chart with Plotly.express in Python 3.9. I created the following table with pandas:
idx cat1 cat2 cat3 cat4
0 A 0.98 0.93 0.550 1.00
1 B 0.92 0.80 0.865 1.00
2 C 0.91 0.87 0.955 0.96
and I have the following code:
# df is the pandas table
fig = px.bar(df,
x = 'idx',
y=['cat1', 'cat2', 'cat3', 'cat4']
)
colors = ['#dc1a22', ] * 12
colors[2] = '#000000'
fig.update_traces(marker_color = colors, marker_line_color='rgb(8,48,107)',
marker_line_width=1.5, opacity=0.6)
fig.update_layout(barmode='group')
I want to color all bars in all groups in #dc1a22 except the one at third position (colors[2]).
The reality is, that all bars in the first and second group are in #dc1a22 and all bars in the third group are in #000000.
Is there a possibility to color a single bar in a grouped chart?
Might be important: In the future I am trying to color the bars depending on their values.
(0-0.5 -> red, 0.5-0.9 -> yellow, 0.9-1 -> green)