# Plotly express with multiple y-axis

**URL:** <https://community.plotly.com/t/plotly-express-with-multiple-y-axis/73219>\
**Category:** 📊 Plotly Python\
**Tags:** question, bug-reporter\
**Created:** [March 3, 2023, 9:50am UTC](https://community.plotly.com/t/plotly-express-with-multiple-y-axis/73219 "2023-03-03T09:50:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernhard](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@Bernhard](https://community.plotly.com/u/Bernhard)\
**Post date:** [March 3, 2023, 9:50am UTC](https://community.plotly.com/t/plotly-express-with-multiple-y-axis/73219/1 "2023-03-03T09:50:29Z")

</div>

consider the following code

```python
import pandas as pd
import numpy as np
import plotly.express as px

df = pd.DataFrame(
    {'val1':np.random.uniform(low=0.5, high=20, size=(50,)), 
    'val2': np.random.uniform(low=2.5, high=40, size=(50,)),
    'val3': np.random.uniform(low=134.5, high=240, size=(50,)),
    })

fig = px.scatter(df, x = 'val1', y = ['val3', 'val2'])
fig.show()
fig = px.scatter(df, x = 'val1', y = ['val1', 'val2'])
fig.show()
fig = px.scatter(df, x = 'val1', y = ['val1'])
fig.show()
fig = px.scatter(df, x = 'val1', y = 'val1')
fig.show()

```

The first figure shows as expected two traces. However, the second figures shows only val2. This seems to come from the presence of val1 in the list as figure three is empty. If it is not a list like in figure 4, then everything is fine. wtf?  
Has anyone seen that and knows a solution? I want to use the list in a function which gets different y-axis values and sometimes the same as was used for the x-axis.  
Plotly version is 5.9.0

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [March 3, 2023, 9:06pm UTC](https://community.plotly.com/t/plotly-express-with-multiple-y-axis/73219/2 "2023-03-03T21:06:15Z")

</div>

Hi @Bernhard welcome to the forums.

Strange indeed, I did not know that. This seems to work too:

```python
fig = px.scatter(x = df.val1, y = [df.val1, df.val2])

```

The downside is, that you loose the trace names.

Another workaround (pretty ugly and not very satisfying):

```python
import pandas as pd
import numpy as np
import plotly.express as px

# DataFrame
df = pd.DataFrame(
    {'val1':np.random.uniform(low=0.5, high=20, size=(50,)), 
    'val2': np.random.uniform(low=2.5, high=40, size=(50,)),
    'val3': np.random.uniform(low=134.5, high=240, size=(50,)),
    })

# column list & iterator
column_list = ['val1', 'val2']
column_iterator = iter(column_list)

# create figure
fig = px.scatter(
    x=df['val1'], 
    y=[df[col] for col in column_list]
)

# update trace names
fig.for_each_trace(
    lambda x: x.update({'name': next(column_iterator)})
)

```
