# New yaxis per selected df column

**URL:** <https://community.plotly.com/t/new-yaxis-per-selected-df-column/31715>\
**Category:** Dash Python\
**Created:** [November 22, 2019, 9:37am UTC](https://community.plotly.com/t/new-yaxis-per-selected-df-column/31715 "2019-11-22T09:37:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iceberg\_Slim](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@Iceberg\_Slim](https://community.plotly.com/u/Iceberg_Slim)\
**Post date:** [November 22, 2019, 9:37am UTC](https://community.plotly.com/t/new-yaxis-per-selected-df-column/31715/1 "2019-11-22T09:37:10Z")

</div>

I have a basic dash app that graphs some data from a dictionary of dataframes. The first dropdown selects the df, while the second selects the columns of the df to be plotted.

This works well, but I can’t seem to add a new yaxis for each of the plotted columns. First, I tried to change the updateGraph callback to include `yaxis=i` after defining x, y & name. Looking at the documentation, it seems that I can define the yaxis in `go.Scatter` but that I would need to set them as ‘y2’, 'y3, ‘y4’ etc. I’ve also tried to update the layout via `go.Figure.add_trace` in this way but neither has worked. The code is below, where `dict_main` is a dictionary of dataframes of various sizes.

All help is appreciated!

```
data = list(dict_main.keys())
channels = dict_main[data[0]]

app.layout = html.Div(
    [
        html.Div([
            dcc.Dropdown(
                id='data-dropdown',
                options=[{'label': speed, 'value': speed} for speed in data],
                value=list(dict_main.keys())[0],
                searchable=False
            ),
        ], style={'width': '49%', 'display': 'inline-block'}),
        html.Div([
            dcc.Dropdown(
                id='channel-dropdown',
                multi=True
            ),
        ], style={'width': '49%', 'display': 'inline-block'}
        ),
        html.Div([
            dcc.Graph(
                id='Main-Graph',
            ),
        ], style={'width': '98%', 'display': 'inline-block'}
        )
    ]
)

@app.callback(
    Output('channel-dropdown', 'options'),
    [Input('data-dropdown', 'value')])
def update_date_dropdown(speed):
    return [{'label': i, 'value': i} for i in dict_main[speed]]

@app.callback(
    Output('Main-Graph', 'figure'),
    [Input('channel-dropdown', 'value')],
    [State('data-dropdown', 'value')])
def updateGraph(channels, speed):
    if channels:

        return go.Figure(data=[go.Scatter(x=dict_main[speed].index, y=dict_main[speed][i], name=i, yaxis='y2') for i in channels])
    else:
        return go.Figure(data=[])

if __name__ == ' __main__':
    app.run_server()
```

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [November 24, 2019, 3:34am UTC](https://community.plotly.com/t/new-yaxis-per-selected-df-column/31715/2 "2019-11-24T03:34:29Z")

</div>

You could use string formatting, like write `yaxis="y%d" %i` (if channels start at 0 then you need to use `%(i+1)` since axes names start at 1). Also see [https://plot.ly/python/multiple-axes/#multiple-axes](https://plot.ly/python/multiple-axes/#multiple-axes) to see how to control the parameters of your multiple y axes (position etc.)

---

<div class="post-metadata">

**Author:** ![Iceberg\_Slim](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@Iceberg\_Slim](https://community.plotly.com/u/Iceberg_Slim)\
**Post date:** [November 25, 2019, 1:42pm UTC](https://community.plotly.com/t/new-yaxis-per-selected-df-column/31715/3 "2019-11-25T13:42:58Z")

</div>

I tried this, the first axis will appear but it won’t add any more when selecting more traces;

```auto
def updateGraph(channels, test):
    if channels:
        j=1
        my_layout = {}
        my_axis = list("")
        for index, column in enumerate(list(channels)):
            my_layout['yaxis' + str(j)] = {}
            my_layout['yaxis' + str(j)]['title'] = column
            my_axis.append('y' + str(j))
            j=index+1

            return go.Figure(data=[go.Scatter(x=dict_main[test].index, y=dict_main[test][i], name=i, yaxis="y%d" %(j)) for i in channels],layout=my_layout)

```

I also tried to populate ‘my\_axis’ with ‘y1,y2,y3’ etc and then say yaxis=my\_axis but this resulted in the same problem.
