Hi,
I’m trying to add a dataframe that is in the below format as a barchart.
ticker value bar_colour
0 NZDCAD -4.25 Green
1 AUDCAD -3.96 Red
2 EURCAD -2.86 Green
3 GBPCHF -2.49 Black
etc
I’m trying to update the figure via a callback. and the code I currently have is. Essentially I’m trying to loop through each data point and create its own barchart, then combining them. It looks quite inelegant but it is the solution proposed by this thread “Different colors for bars in barchart by their value”
fig = make_subplots(rows=1, cols=1)
for index, label_df in df.iterrows():
trace = go.Bar(x=[label_df['ticker']],
y=[label_df['value']],
marker={'color': label_df['bar_colour']})
fig.add_trace(trace, row=1, col=1,secondary_y=False)
return fig
The chart however is empty, with the y axis looks very funny and I think is somehow is the problem.
So my question is two part
- Is there an easier way to achieve my goal?
- Why isn’t my code working?
Thanks very much
Felton