Colors in grouped and stacked bar plot

Hi! I’m trying to make a grouped + stacked bar chart using plotly express. My dataframe looks like this


I have used the following code to build the plot:


fig=, x=‘Provider’, y=[‘4G (%)’,‘4G Roaming (%)’],
color=‘Aggregate Date’, barmode=‘group’,color_discrete_sequence=color4g+color4gRoaming)

which displays the desired plot, however, I have not found the correct way to differentiate the colors of the values from the first column (‘4G (%)’) from the second column (‘4G Roaming (%)’).

I need that the colors from the ‘4G Roaming (%)’ column to be an opacity version of the ones of ‘4G (%)’, and for such I’m using explicitly the command color_discrete_sequence=color4g+color4gRoaming, however that does not seem to be working.

Any ideas for a solution?

Thanks in advance!

HI @sbermudezf could you provide your DataFrame so that it can be copy&pasted instead of an image?

1 Like

Try and Rearrange your color scheme. Would suggest…
color4g = [‘rgb(213,3,85)’, ‘rgba(213,3,85,0.5)’, ‘rgb(255,152,0)’, ‘rgba(255,152,0,0.5)’ …]

Perhaps, you are providing 4 colors for color4g and 4 for color4gRoaming and then concatanating both to provide 8 colors. Whereas dataset has only 4 colors required (2019,20,21 and 22). Hence, plotly uses first 4 colors.

See if it helps.


1 Like