Reputation: 23
I'm looking to get help in creating a bar chart in Dash (plotly) and having more than one color for all bars,at the moment they are all blue.
e.g.
pv = pd.pivot_table(df, index=['customer_name2'], columns=['FY'], values=['amount'], aggfunc=sum, fill_value=0)
pv2 = pv.reindex(pv['amount'].sort_values(by='FY17', ascending=True).index).head(x_bottom)
trace1 = go.Bar(x=pv2.index, y=pv2[('amount','FY17')], name='Revenue')
graphs.append(html.Div(dcc.Graph(
id='chart_id_6',
figure={
'data': [trace1],
'layout': {
'title': 'Bottom ' + str(x_bottom) + ' Customers'
}
})))
Upvotes: 2
Views: 8898
Reputation: 41
For json format below code will work :
graphs.append(html.Div(dcc.Graph(
id='chart_id_6',
figure={
'data': [{'x':pv2.index, 'y': pv2[('amount','FY17')],
'marker': {'color': ['#b50000', '#e63535', '#fa8989']}}],
'layout': {
'title': 'Bottom ' + str(x_bottom) + ' Customers'
}
})))
Upvotes: 0
Reputation: 1322
You can pass a list of colors, with a different color for each Bar.
trace1 = go.Bar(
x=pv2.index,
y=pv2[('amount','FY17')],
name='Revenue',
marker=dict(
color=['rgba(204,204,204,1)',
'rgba(222,45,38,0.8)',
...])
)
See https://plot.ly/python/bar-charts/ chapter: Customizing Individual Bar Colors
This might also help: Different colors for bars in barchart by their value
Upvotes: 4