# Select different trace using buttons

**URL:** <https://community.plotly.com/t/select-different-trace-using-buttons/9713>\
**Category:** 📊 Plotly Python\
**Created:** [April 16, 2018, 12:19pm UTC](https://community.plotly.com/t/select-different-trace-using-buttons/9713 "2018-04-16T12:19:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![l3r4nd](https://avatars.discourse-cdn.com/v4/letter/l/f1d935/32.png) [@l3r4nd](https://community.plotly.com/u/l3r4nd)\
**Post date:** [April 16, 2018, 12:19pm UTC](https://community.plotly.com/t/select-different-trace-using-buttons/9713/1 "2018-04-16T12:19:23Z")

</div>

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)
> 
> ```

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [April 16, 2018, 8:12pm UTC](https://community.plotly.com/t/select-different-trace-using-buttons/9713/2 "2018-04-16T20:12:18Z")

</div>

@l3r4nd Take a look at these examples on how to define buttons: [https://plot.ly/python/custom-buttons/](https://plot.ly/python/custom-buttons/)
