You have to pass the colorscale
argument as part of the marker
parameter dictionary, and the color
argument to take the y
values like this:
import plotly.graph_objs as go
x = ['Albania', 'Denmark', 'France', 'Finland', 'USSR']
y = [4, 2, 3, 5, 9]
fig = go.FigureWidget(data=[go.Bar(x=x, y=y,
marker={'color': y,
'colorscale': 'Viridis'})])
fig
This chart has one trace, and does not show a legend. If you want to show the legend, you can make each bar a different trace, by passing a list of go.Bar
s.
(I might be doing something wrong, but the scolorscale here is not taking Viridis and using the default scale.)
import plotly.graph_objs as go
fig2 = go.FigureWidget(data=[go.Bar(x=[x],
y=[y],
name=x,
marker={'color': y,
'colorscale': 'Viridis'})
for x, y in zip(x, y)])
fig2
Hope that helps!