0

I have a question regarding bar chart color customization. I have a Grouped Bar Chart like the one below.

I want to know how it is possible to customize only the first column of each occurrence.

enter image description here

Part of the code I created to build this chart is below:

# Create the chart
colors = ['royalblue'] * len(df5)

for i in range(0,len(df5),1):

if df5['wip_higher'][i] == 0:
    colors[df5.index[i]] = 'palegreen'
    
elif df5['wip_higher'][i] == 1:
    colors[df5.index[i]] = 'moccasin'
    
elif df5['wip_higher'][i] == 2:
    colors[df5.index[i]] = 'goldenrod'
    
elif df5['wip_higher'][i] == 3:
    colors[df5.index[i]] = 'salmon'

elif df5['wip_higher'][i] == 4:
    colors[df5.index[i]] = 'black'


fig = px.bar(df5,
            x='Issue key',
            y=['time_wip', 'planned_effort'],
            template='plotly_white',
            text_auto=True,
            barmode='group',
            width=1000,
            labels={'y': 'Time in WIP (in Days)',
                'x': 'Issue Key'}
            )

fig.update_layout(legend=dict(orientation="h",
                            yanchor="bottom",
                            y=1.02,
                            xanchor="right",
                            x=1),
                legend_title_text='')

fig.update_traces(marker_color=colors)

fig.show()

I have tried different approaches, but none worked.

I appreciate your help.

Regards, Marcelo

3
  • 1
    You will have to create two subplots on the y axis, one envolving the first bar and the other envolving the second bar. After that just play a little bit with the colour parameter and parabin parabum Commented Aug 5, 2022 at 13:09
  • 1
    Not sure, but I feel this may give an idea: stackoverflow.com/questions/72814480/… Commented Aug 5, 2022 at 13:10
  • 1
    I think this link help to you Commented Aug 5, 2022 at 13:12

2 Answers 2

1

How about creating them as seperate traces and style each individually?

fig = px.Bar()
fig.add_trace(go.Bar(x=df['Issue Key'], y=df['time_wip']...style as needed)
fig.add_trace(go.Bar(x=df['Issue Key'], y=df['planned_effort']... style as needed)
fig.update_layout(barmode='group')
Sign up to request clarification or add additional context in comments.

Comments

1

thanks for all the answers, I found in the documentation (which is not very well organized) this option. I tried and I could solve it without changing the rest of my code.

enter image description here

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.