Stacked Bar Specify Colors

I have created a stacked bar chart but can’t figure out to set the color for each element within the bar. Currently my stacked bar chart is just using the default color scheme

Check out the examples here: https://plot.ly/python/bar-charts/

I have the same question. The documentation does not answer it. Judging by the error message I got, it seems like Plotly may not support this feature…?

     you can use something like this. i was struggling as well.

figure={
‘data’: [{‘x’: freq.index, ‘y’: freq.values, ‘type’: ‘bar’,‘marker’:dict(color=“MediumPurple”)}],
‘layout’: layout

1 Like

import plotly.graph_objs as go
go.Bar(
x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012],
y=[219, 146, 112, 127, 124, 180, 236, 207, 236, 263,
350, 430, 474, 526, 488, 537, 500, 439],
name=‘Rest of world’,
marker=go.bar.Marker(
color=‘rgb(55, 83, 109)’
)
),

for reference this format works in javascript
Can use ‘red’, ‘blue’, ‘green’ etc instead of ‘rgba(222,45,38,0.8)’ format.
if nominating a single value for color, all the columns for the category as the same color.
if want a different colour for each column, have to nominate a list of colors.

var trace2 = {
x: post_code,
y: Count_Unit_Bus,
name: ‘Buses’,
type: ‘bar’,
marker:{ color: ‘rgba(222,45,38,0.8)’ },
};

(repeat for each category plotted in a stacked bar chart)