Hello,
is there a way we can select different trace using the buttons? below is my attempt trying to do it using a for loop but itβs not working and I have no idea how to, please help.
Code
import plotly.offline as py
from plotly import graph_objs as go
py.init_notebook_mode(connected = False)
data = []
Layout = []
countries = data['country'].unique()
i = 0
for country in countries:
trace = go.Bar(
x = data.loc[data['country'] == country, 'sector'].value_counts().index,
y = data.loc[data['country'] == country, 'sector'].value_counts().values,
)
data.append(trace)
layout = go.Layout(
updatemenus = [
dict(
type = 'dropdown',
buttons = [
dict(
label = country,
args = [data[i]],
method = 'restyle'
),
]
)]
)
i += 1
Layout.append(layout)
fig = go.Figure(data = data, layout = Layout)
py.iplot(fig)